#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
using ll = long long;
const int N=1e3;
int l[N], r[N];
vector<int> adj[N];
int nxt=0;
int col[N];
void dfs(int u, int p, int c) {
col[u]=c;
l[u]=nxt++;
for(auto&v:adj[u]) {
if (v==p) continue;
dfs(v,u,!c);
}
r[u]=nxt++;
}
vector<int> label(int n, int k, vector<int>u, vector<int> v) {
forn(i,n) adj[i].clear(); nxt=0;
forn(i,n-1) {
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
dfs(0,-1,0);
vector<int> ans(n);
forn(i,n) {
if (col[i]) {
ans[i]=l[i];
} else {
ans[i]=r[i];
}
}
set<int> s; forn(i,n) s.insert(ans[i]);
int mex=0;
map<int,int> c;
for(auto&x:s) c[x]=mex++;
forn(i,n) ans[i]=c[ans[i]];
return ans;
}
int is_ancestor(int l, int r, int y) {
//x is anc of y
return l <= y && y <= r;
}
int find_next_station(int s, int t, vector<int> adj) {
//cout<<"? "<<s<<' '<<t<<": "; for(auto&x:adj) cout<<x<<' '; cout<<'\n';
if (adj.size()==1) return adj[0];
if (s > adj.back()) {
int l=2*adj[1]-1;
int r=2*s;
if (is_ancestor(l,r,2*t)) {
for (int i=1; i<adj.size()-1; ++i) {
int l=2*adj[i], r=2*adj[i+1]-1;
if (is_ancestor(l,r,2*t)) return adj[i];
}
return adj.back();
} else {
return adj[0];
}
} else {
int l=2*s;
int r=2*adj[adj.size()-2]+1;
if (is_ancestor(l,r,2*t)) {
for (int i=1; i<adj.size()-1; ++i) {
int l=2*adj[i-1]+1, r=2*adj[i];
if (is_ancestor(l,r,2*t)) return adj[i];
}
return adj[0];
} else {
return adj.back();
}
}
}
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:4:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
4 | #define forn(i,n) for(int i=0;i<n;++i)
| ^~~
stations.cpp:25:2: note: in expansion of macro 'forn'
25 | forn(i,n) adj[i].clear(); nxt=0;
| ^~~~
stations.cpp:25:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
25 | forn(i,n) adj[i].clear(); nxt=0;
| ^~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:60:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int i=1; i<adj.size()-1; ++i) {
| ~^~~~~~~~~~~~~
stations.cpp:72:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i=1; i<adj.size()-1; ++i) {
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
381 ms |
756 KB |
Output is correct |
2 |
Correct |
411 ms |
664 KB |
Output is correct |
3 |
Correct |
810 ms |
532 KB |
Output is correct |
4 |
Correct |
633 ms |
528 KB |
Output is correct |
5 |
Correct |
559 ms |
544 KB |
Output is correct |
6 |
Correct |
399 ms |
672 KB |
Output is correct |
7 |
Correct |
381 ms |
672 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
4 ms |
632 KB |
Output is correct |
10 |
Correct |
0 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
409 ms |
660 KB |
Output is correct |
2 |
Correct |
366 ms |
676 KB |
Output is correct |
3 |
Correct |
648 ms |
536 KB |
Output is correct |
4 |
Correct |
568 ms |
536 KB |
Output is correct |
5 |
Correct |
538 ms |
528 KB |
Output is correct |
6 |
Correct |
352 ms |
660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
383 ms |
660 KB |
Output is correct |
2 |
Correct |
431 ms |
676 KB |
Output is correct |
3 |
Correct |
787 ms |
528 KB |
Output is correct |
4 |
Correct |
417 ms |
544 KB |
Output is correct |
5 |
Correct |
525 ms |
540 KB |
Output is correct |
6 |
Correct |
379 ms |
664 KB |
Output is correct |
7 |
Correct |
308 ms |
668 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
628 KB |
Output is correct |
11 |
Correct |
484 ms |
672 KB |
Output is correct |
12 |
Correct |
392 ms |
788 KB |
Output is correct |
13 |
Correct |
413 ms |
672 KB |
Output is correct |
14 |
Correct |
391 ms |
672 KB |
Output is correct |
15 |
Correct |
48 ms |
620 KB |
Output is correct |
16 |
Correct |
62 ms |
728 KB |
Output is correct |
17 |
Correct |
71 ms |
828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
499 ms |
556 KB |
Output is correct |
2 |
Correct |
537 ms |
548 KB |
Output is correct |
3 |
Correct |
447 ms |
532 KB |
Output is correct |
4 |
Correct |
2 ms |
628 KB |
Output is correct |
5 |
Correct |
4 ms |
628 KB |
Output is correct |
6 |
Correct |
0 ms |
748 KB |
Output is correct |
7 |
Correct |
380 ms |
416 KB |
Output is correct |
8 |
Correct |
732 ms |
528 KB |
Output is correct |
9 |
Correct |
604 ms |
532 KB |
Output is correct |
10 |
Correct |
436 ms |
544 KB |
Output is correct |
11 |
Correct |
4 ms |
632 KB |
Output is correct |
12 |
Correct |
4 ms |
748 KB |
Output is correct |
13 |
Correct |
5 ms |
492 KB |
Output is correct |
14 |
Correct |
3 ms |
628 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
444 ms |
664 KB |
Output is correct |
17 |
Correct |
424 ms |
540 KB |
Output is correct |
18 |
Correct |
394 ms |
588 KB |
Output is correct |
19 |
Correct |
388 ms |
528 KB |
Output is correct |
20 |
Correct |
481 ms |
564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
449 ms |
756 KB |
Output is correct |
2 |
Correct |
357 ms |
740 KB |
Output is correct |
3 |
Correct |
621 ms |
544 KB |
Output is correct |
4 |
Correct |
635 ms |
416 KB |
Output is correct |
5 |
Correct |
458 ms |
592 KB |
Output is correct |
6 |
Correct |
354 ms |
780 KB |
Output is correct |
7 |
Correct |
450 ms |
660 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
444 KB |
Output is correct |
10 |
Correct |
0 ms |
620 KB |
Output is correct |
11 |
Correct |
445 ms |
672 KB |
Output is correct |
12 |
Correct |
476 ms |
668 KB |
Output is correct |
13 |
Correct |
753 ms |
528 KB |
Output is correct |
14 |
Correct |
600 ms |
656 KB |
Output is correct |
15 |
Correct |
578 ms |
740 KB |
Output is correct |
16 |
Correct |
335 ms |
748 KB |
Output is correct |
17 |
Correct |
519 ms |
536 KB |
Output is correct |
18 |
Correct |
302 ms |
932 KB |
Output is correct |
19 |
Correct |
411 ms |
920 KB |
Output is correct |
20 |
Correct |
391 ms |
904 KB |
Output is correct |
21 |
Correct |
40 ms |
548 KB |
Output is correct |
22 |
Correct |
62 ms |
600 KB |
Output is correct |
23 |
Correct |
110 ms |
848 KB |
Output is correct |
24 |
Correct |
5 ms |
720 KB |
Output is correct |
25 |
Correct |
4 ms |
652 KB |
Output is correct |
26 |
Correct |
4 ms |
624 KB |
Output is correct |
27 |
Correct |
2 ms |
620 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
369 ms |
532 KB |
Output is correct |
30 |
Correct |
435 ms |
532 KB |
Output is correct |
31 |
Correct |
392 ms |
444 KB |
Output is correct |
32 |
Correct |
476 ms |
536 KB |
Output is correct |
33 |
Correct |
432 ms |
852 KB |
Output is correct |
34 |
Correct |
247 ms |
964 KB |
Output is correct |
35 |
Correct |
333 ms |
780 KB |
Output is correct |
36 |
Correct |
426 ms |
868 KB |
Output is correct |
37 |
Correct |
419 ms |
1048 KB |
Output is correct |
38 |
Correct |
329 ms |
776 KB |
Output is correct |
39 |
Correct |
382 ms |
832 KB |
Output is correct |
40 |
Correct |
399 ms |
832 KB |
Output is correct |
41 |
Correct |
439 ms |
900 KB |
Output is correct |
42 |
Correct |
38 ms |
788 KB |
Output is correct |
43 |
Correct |
90 ms |
832 KB |
Output is correct |
44 |
Correct |
120 ms |
704 KB |
Output is correct |
45 |
Correct |
137 ms |
660 KB |
Output is correct |
46 |
Correct |
271 ms |
784 KB |
Output is correct |
47 |
Correct |
269 ms |
876 KB |
Output is correct |
48 |
Correct |
34 ms |
940 KB |
Output is correct |
49 |
Correct |
37 ms |
876 KB |
Output is correct |