#include <bits/stdc++.h>
#include "stations.h"
#define pii pair<int,int>
#define in first
#define out second
#define mp make_pair
using namespace std;
vector<int> label(int n ,int k , vector<int> u , vector<int> v){
vector<int> ans(n) ;
vector<int> adj[n] ;
for(int i=0;i<n-1;i++) {
adj[u[i]].push_back(v[i]) ;
adj[v[i]].push_back(u[i]) ;
}
int tim = 0 ;
vector<int> inn(n) , outt(n) ;
function<void(int,int)> dfs = [&](int a, int p){
inn[a]=tim++;
for(int x :adj[a]){
if(x!=p){
dfs(x,a) ;
}
}
outt[a]=++tim ;
};
dfs(0,0) ;
for(int i=0;i<n;i++)
ans[i]=inn[i]+((outt[i])<<11);
return ans ;
}
pii get(int x){
return mp(x%(1<<11),(x>>11)) ;
}
bool ancestor(pii s, pii b){
return (s.in<=b.in&&b.out<=s.out);
}
int find_next_station(int s ,int t, vector<int> ne){
pii ss = get(s) , tt = get(t) ;
if(ancestor(ss,tt)^1){
for(int x : ne){
if(ancestor(get(x),ss)){
return x ;
}
}
}
for(int x : ne){
if(ancestor(get(x),ss)^1 && ancestor(get(x),tt)){
return x ;
}
}
if(s==t) return s ;
return 1 ;
}
/*int main(){
vector<int> u= {0,1,2} , v = {1,2,3} ;
vector<int> res = label(4,1000000,u,v) ;
for(int x : res) cout << x <<" " ;
cout << endl ;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(i!=j){
cout << i << " "<< j << ": " << find_next_station(i,j,adj[i]) << endl ;
}
}
}
return 0 ;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
456 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=40960 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
328 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=4079616 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
468 KB |
Invalid labels (values out of range). scenario=1, k=1000000, vertex=0, label=4083712 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
905 ms |
476 KB |
Output is correct |
2 |
Correct |
671 ms |
400 KB |
Output is correct |
3 |
Correct |
592 ms |
400 KB |
Output is correct |
4 |
Correct |
3 ms |
480 KB |
Output is correct |
5 |
Correct |
5 ms |
472 KB |
Output is correct |
6 |
Correct |
2 ms |
472 KB |
Output is correct |
7 |
Correct |
657 ms |
400 KB |
Output is correct |
8 |
Correct |
1067 ms |
400 KB |
Output is correct |
9 |
Correct |
723 ms |
400 KB |
Output is correct |
10 |
Correct |
655 ms |
404 KB |
Output is correct |
11 |
Correct |
7 ms |
472 KB |
Output is correct |
12 |
Correct |
5 ms |
472 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
472 KB |
Output is correct |
15 |
Correct |
2 ms |
472 KB |
Output is correct |
16 |
Correct |
594 ms |
400 KB |
Output is correct |
17 |
Correct |
567 ms |
400 KB |
Output is correct |
18 |
Correct |
627 ms |
528 KB |
Output is correct |
19 |
Correct |
557 ms |
528 KB |
Output is correct |
20 |
Correct |
500 ms |
400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
517 ms |
620 KB |
Partially correct |
2 |
Partially correct |
468 ms |
520 KB |
Partially correct |
3 |
Partially correct |
1190 ms |
520 KB |
Partially correct |
4 |
Partially correct |
693 ms |
400 KB |
Partially correct |
5 |
Partially correct |
634 ms |
400 KB |
Partially correct |
6 |
Partially correct |
562 ms |
784 KB |
Partially correct |
7 |
Partially correct |
549 ms |
620 KB |
Partially correct |
8 |
Partially correct |
3 ms |
472 KB |
Partially correct |
9 |
Partially correct |
4 ms |
472 KB |
Partially correct |
10 |
Partially correct |
1 ms |
472 KB |
Partially correct |
11 |
Partially correct |
587 ms |
484 KB |
Partially correct |
12 |
Partially correct |
683 ms |
528 KB |
Partially correct |
13 |
Partially correct |
1018 ms |
428 KB |
Partially correct |
14 |
Partially correct |
736 ms |
400 KB |
Partially correct |
15 |
Partially correct |
625 ms |
400 KB |
Partially correct |
16 |
Partially correct |
538 ms |
528 KB |
Partially correct |
17 |
Partially correct |
665 ms |
400 KB |
Partially correct |
18 |
Partially correct |
483 ms |
544 KB |
Partially correct |
19 |
Partially correct |
625 ms |
776 KB |
Partially correct |
20 |
Partially correct |
551 ms |
528 KB |
Partially correct |
21 |
Partially correct |
72 ms |
400 KB |
Partially correct |
22 |
Partially correct |
70 ms |
544 KB |
Partially correct |
23 |
Partially correct |
141 ms |
528 KB |
Partially correct |
24 |
Partially correct |
5 ms |
472 KB |
Partially correct |
25 |
Partially correct |
5 ms |
472 KB |
Partially correct |
26 |
Partially correct |
5 ms |
480 KB |
Partially correct |
27 |
Partially correct |
5 ms |
484 KB |
Partially correct |
28 |
Partially correct |
2 ms |
480 KB |
Partially correct |
29 |
Partially correct |
571 ms |
508 KB |
Partially correct |
30 |
Partially correct |
657 ms |
488 KB |
Partially correct |
31 |
Partially correct |
569 ms |
528 KB |
Partially correct |
32 |
Partially correct |
551 ms |
400 KB |
Partially correct |
33 |
Partially correct |
592 ms |
400 KB |
Partially correct |
34 |
Partially correct |
358 ms |
532 KB |
Partially correct |
35 |
Partially correct |
508 ms |
736 KB |
Partially correct |
36 |
Partially correct |
501 ms |
616 KB |
Partially correct |
37 |
Partially correct |
511 ms |
648 KB |
Partially correct |
38 |
Partially correct |
583 ms |
648 KB |
Partially correct |
39 |
Partially correct |
586 ms |
652 KB |
Partially correct |
40 |
Partially correct |
507 ms |
612 KB |
Partially correct |
41 |
Partially correct |
531 ms |
616 KB |
Partially correct |
42 |
Partially correct |
68 ms |
528 KB |
Partially correct |
43 |
Partially correct |
123 ms |
528 KB |
Partially correct |
44 |
Partially correct |
187 ms |
492 KB |
Partially correct |
45 |
Partially correct |
211 ms |
528 KB |
Partially correct |
46 |
Partially correct |
370 ms |
528 KB |
Partially correct |
47 |
Partially correct |
404 ms |
528 KB |
Partially correct |
48 |
Partially correct |
93 ms |
580 KB |
Partially correct |
49 |
Partially correct |
69 ms |
656 KB |
Partially correct |