#include <bits/stdc++.h>
#include "stations.h"
#warning That's not FB, that's my FB
using namespace std;
vector<int> g[1005];
int h[1005], pre[1005], post[1005], tmp, tmp2;
bool viz[1005];
void dfs(int nod, int tata)
{
viz[nod] = true;
//cout << "ya" << nod << endl;
if (h[nod] % 2 == 0)
{
tmp++;
pre[nod] = tmp;
}
for (auto vecin : g[nod])
{
if (vecin != tata and !viz[vecin])
{
h[vecin] = 1 + h[nod];
dfs(vecin, nod);
}
}
if (h[nod] % 2 == 1)
{
tmp++;
post[nod] = tmp;
}
}
vector<int> label (int n, int k, vector<int> u, vector<int> v)
{
for (int i = 0; i < n; i++)
g[i].clear(), viz[i] = false;
for (int i = 0; i < n; i++)
g[u[i]].push_back(v[i]), g[v[i]].push_back(u[i]);
vector<int> ans(n);
h[0] = 0;
tmp = -1;
tmp2 = -1;
dfs(0, -1);
//for (int i = 0; i < n; i++)
// cout << pre[i] << ' ' << post[i] << endl;
for (int i = 0; i < n; i++)
{
if (h[i] % 2 == 0)
ans[i] = pre[i];
else
ans[i] = post[i];
}
vector<pair<int,int>> pans;
for (int i = 0; i < n; i++)
pans.push_back({ans[i],i});
sort(pans.begin(), pans.end());
for (int i = 0; i < n; i++)
ans[pans[i].second] = i;
//for (int i = 0; i < n; i++)
// cout << ans[i] << '\n';
return ans;
}
int find_next_station(int s, int f, vector<int> c)
{
sort(c.begin(), c.end());
if (c.size() == 1)
return c[0];
if (s < c[0])
{
///pre
int mxf = c[c.size() - 2];
if (f > s and f <= mxf)
{
int pz;
for (int i = c.size() - 2; i >= 0; i--)
if (c[i] >= f)
pz = i;
return c[pz];
}
else
return c.back();
}
else
{
///post
int mnf = c[1];
if (f >= mnf and f < s)
{
int pz;
for (int i = 1; i < c.size(); i++)
if (c[i] <= f)
pz = i;
return c[pz];
}
else
return c[0];
}
}
Compilation message
stations.cpp:3:2: warning: #warning That's not FB, that's my FB [-Wcpp]
3 | #warning That's not FB, that's my FB
| ^~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:93:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for (int i = 1; i < c.size(); i++)
| ~~^~~~~~~~~~
stations.cpp:96:24: warning: 'pz' may be used uninitialized in this function [-Wmaybe-uninitialized]
96 | return c[pz];
| ^
stations.cpp:81:24: warning: 'pz' may be used uninitialized in this function [-Wmaybe-uninitialized]
81 | return c[pz];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
856 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
628 ms |
684 KB |
Output is correct |
2 |
Correct |
466 ms |
684 KB |
Output is correct |
3 |
Correct |
461 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
772 KB |
Output is correct |
5 |
Correct |
2 ms |
772 KB |
Output is correct |
6 |
Correct |
0 ms |
776 KB |
Output is correct |
7 |
Correct |
394 ms |
684 KB |
Output is correct |
8 |
Correct |
631 ms |
684 KB |
Output is correct |
9 |
Correct |
494 ms |
684 KB |
Output is correct |
10 |
Correct |
427 ms |
688 KB |
Output is correct |
11 |
Correct |
3 ms |
764 KB |
Output is correct |
12 |
Correct |
2 ms |
776 KB |
Output is correct |
13 |
Correct |
2 ms |
768 KB |
Output is correct |
14 |
Incorrect |
3 ms |
768 KB |
Wrong query response. |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
856 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |