#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)
{
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 - 1; 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;
//cout << "ya" << endl;
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:94:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for (int i = 1; i < c.size(); i++)
| ~~^~~~~~~~~~
stations.cpp:97:24: warning: 'pz' may be used uninitialized in this function [-Wmaybe-uninitialized]
97 | return c[pz];
| ^
stations.cpp:82:24: warning: 'pz' may be used uninitialized in this function [-Wmaybe-uninitialized]
82 | return c[pz];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
370 ms |
940 KB |
Output is correct |
2 |
Correct |
316 ms |
940 KB |
Output is correct |
3 |
Correct |
586 ms |
940 KB |
Output is correct |
4 |
Correct |
471 ms |
684 KB |
Output is correct |
5 |
Correct |
423 ms |
684 KB |
Output is correct |
6 |
Correct |
262 ms |
800 KB |
Output is correct |
7 |
Correct |
272 ms |
800 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
684 KB |
Output is correct |
2 |
Correct |
355 ms |
684 KB |
Output is correct |
3 |
Correct |
512 ms |
684 KB |
Output is correct |
4 |
Correct |
370 ms |
684 KB |
Output is correct |
5 |
Correct |
323 ms |
800 KB |
Output is correct |
6 |
Correct |
277 ms |
940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
320 ms |
940 KB |
Output is correct |
2 |
Correct |
258 ms |
684 KB |
Output is correct |
3 |
Correct |
530 ms |
796 KB |
Output is correct |
4 |
Correct |
379 ms |
868 KB |
Output is correct |
5 |
Correct |
350 ms |
684 KB |
Output is correct |
6 |
Correct |
293 ms |
800 KB |
Output is correct |
7 |
Correct |
246 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
355 ms |
684 KB |
Output is correct |
12 |
Correct |
239 ms |
788 KB |
Output is correct |
13 |
Correct |
267 ms |
1048 KB |
Output is correct |
14 |
Correct |
267 ms |
684 KB |
Output is correct |
15 |
Correct |
29 ms |
768 KB |
Output is correct |
16 |
Correct |
36 ms |
684 KB |
Output is correct |
17 |
Correct |
51 ms |
800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
586 ms |
684 KB |
Output is correct |
2 |
Correct |
427 ms |
684 KB |
Output is correct |
3 |
Correct |
396 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
776 KB |
Output is correct |
7 |
Correct |
383 ms |
800 KB |
Output is correct |
8 |
Correct |
615 ms |
684 KB |
Output is correct |
9 |
Correct |
475 ms |
684 KB |
Output is correct |
10 |
Correct |
429 ms |
684 KB |
Output is correct |
11 |
Correct |
2 ms |
776 KB |
Output is correct |
12 |
Correct |
3 ms |
768 KB |
Output is correct |
13 |
Correct |
2 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
0 ms |
776 KB |
Output is correct |
16 |
Correct |
351 ms |
684 KB |
Output is correct |
17 |
Correct |
346 ms |
684 KB |
Output is correct |
18 |
Correct |
339 ms |
684 KB |
Output is correct |
19 |
Correct |
328 ms |
684 KB |
Output is correct |
20 |
Correct |
356 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
940 KB |
Output is correct |
2 |
Correct |
312 ms |
684 KB |
Output is correct |
3 |
Correct |
631 ms |
684 KB |
Output is correct |
4 |
Correct |
473 ms |
688 KB |
Output is correct |
5 |
Correct |
395 ms |
684 KB |
Output is correct |
6 |
Correct |
276 ms |
940 KB |
Output is correct |
7 |
Correct |
304 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
776 KB |
Output is correct |
9 |
Correct |
1 ms |
764 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
11 |
Correct |
308 ms |
684 KB |
Output is correct |
12 |
Correct |
345 ms |
684 KB |
Output is correct |
13 |
Correct |
614 ms |
684 KB |
Output is correct |
14 |
Correct |
480 ms |
684 KB |
Output is correct |
15 |
Correct |
387 ms |
684 KB |
Output is correct |
16 |
Correct |
275 ms |
684 KB |
Output is correct |
17 |
Correct |
426 ms |
684 KB |
Output is correct |
18 |
Correct |
287 ms |
788 KB |
Output is correct |
19 |
Correct |
322 ms |
788 KB |
Output is correct |
20 |
Correct |
294 ms |
684 KB |
Output is correct |
21 |
Correct |
32 ms |
768 KB |
Output is correct |
22 |
Correct |
55 ms |
764 KB |
Output is correct |
23 |
Correct |
60 ms |
684 KB |
Output is correct |
24 |
Correct |
4 ms |
764 KB |
Output is correct |
25 |
Correct |
2 ms |
776 KB |
Output is correct |
26 |
Correct |
3 ms |
768 KB |
Output is correct |
27 |
Correct |
1 ms |
768 KB |
Output is correct |
28 |
Correct |
0 ms |
772 KB |
Output is correct |
29 |
Correct |
395 ms |
684 KB |
Output is correct |
30 |
Correct |
387 ms |
684 KB |
Output is correct |
31 |
Correct |
352 ms |
684 KB |
Output is correct |
32 |
Correct |
353 ms |
684 KB |
Output is correct |
33 |
Correct |
348 ms |
684 KB |
Output is correct |
34 |
Correct |
235 ms |
716 KB |
Output is correct |
35 |
Correct |
318 ms |
940 KB |
Output is correct |
36 |
Correct |
326 ms |
1044 KB |
Output is correct |
37 |
Correct |
349 ms |
792 KB |
Output is correct |
38 |
Correct |
395 ms |
1188 KB |
Output is correct |
39 |
Correct |
307 ms |
1040 KB |
Output is correct |
40 |
Correct |
286 ms |
812 KB |
Output is correct |
41 |
Correct |
290 ms |
796 KB |
Output is correct |
42 |
Correct |
30 ms |
760 KB |
Output is correct |
43 |
Correct |
54 ms |
716 KB |
Output is correct |
44 |
Correct |
83 ms |
716 KB |
Output is correct |
45 |
Correct |
107 ms |
768 KB |
Output is correct |
46 |
Correct |
187 ms |
684 KB |
Output is correct |
47 |
Correct |
196 ms |
684 KB |
Output is correct |
48 |
Correct |
47 ms |
768 KB |
Output is correct |
49 |
Correct |
39 ms |
1120 KB |
Output is correct |