#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
int pre[1005],pst[1005],dist[1005],cnt;
vector<int> AL[1005];
void dfs(int u){
pre[u]=cnt++;
for(int v:AL[u]){
if(pre[v]==-1){
dist[v]=dist[u]+1;
dfs(v);
}
}
pst[u]=cnt++;
}
vector<int> label(int n,int k,vector<int> u,vector<int> v){
vector<int> l(n);
for(int i=0;i<n;++i)AL[i].clear();
memset(pre,-1,sizeof pre);
memset(pst,-1,sizeof pst);
cnt=0;
for(int i=0;i<n-1;++i){
AL[u[i]].pb(v[i]);
AL[v[i]].pb(u[i]);
}
dist[0]=0;dfs(0);
vector<int> d;
for(int i=0;i<n;++i){
if(dist[i]%2)d.pb(pre[i]);
else d.pb(pst[i]);
}
sort(all(d));
d.resize(unique(all(d))-d.begin());
for(int i=0;i<n;++i){
if(dist[i]%2)l[i]=lower_bound(all(d),pre[i])-d.begin();
else l[i]=lower_bound(all(d),pst[i])-d.begin();
}
return l;
}
int find_next_station(int s,int t,vector<int> c){
int n=c.size();
if(s<c[0]){
int pv=s;
for(int i=0;i<n-1;++i){
if(pv+1<=t&&t<=c[i])return c[i];
pv=c[i];
}
return c[n-1];
}
else{
int pv=s;
for(int i=n-1;i>=1;--i){
if(c[i]<=t&&t<=pv-1)return c[i];
pv=c[i];
}
return c[0];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
556 ms |
508 KB |
Output is correct |
2 |
Correct |
417 ms |
528 KB |
Output is correct |
3 |
Correct |
873 ms |
504 KB |
Output is correct |
4 |
Correct |
633 ms |
528 KB |
Output is correct |
5 |
Correct |
771 ms |
528 KB |
Output is correct |
6 |
Correct |
472 ms |
528 KB |
Output is correct |
7 |
Correct |
452 ms |
528 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
414 ms |
520 KB |
Output is correct |
2 |
Correct |
600 ms |
528 KB |
Output is correct |
3 |
Correct |
918 ms |
504 KB |
Output is correct |
4 |
Correct |
692 ms |
500 KB |
Output is correct |
5 |
Correct |
561 ms |
600 KB |
Output is correct |
6 |
Correct |
425 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
506 ms |
644 KB |
Output is correct |
2 |
Correct |
462 ms |
516 KB |
Output is correct |
3 |
Correct |
859 ms |
400 KB |
Output is correct |
4 |
Correct |
626 ms |
512 KB |
Output is correct |
5 |
Correct |
558 ms |
528 KB |
Output is correct |
6 |
Correct |
484 ms |
588 KB |
Output is correct |
7 |
Correct |
409 ms |
532 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
596 KB |
Output is correct |
11 |
Correct |
622 ms |
528 KB |
Output is correct |
12 |
Correct |
522 ms |
616 KB |
Output is correct |
13 |
Correct |
470 ms |
736 KB |
Output is correct |
14 |
Correct |
446 ms |
532 KB |
Output is correct |
15 |
Correct |
53 ms |
596 KB |
Output is correct |
16 |
Correct |
58 ms |
528 KB |
Output is correct |
17 |
Correct |
101 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
861 ms |
644 KB |
Output is correct |
2 |
Correct |
589 ms |
500 KB |
Output is correct |
3 |
Correct |
526 ms |
400 KB |
Output is correct |
4 |
Correct |
3 ms |
476 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
590 ms |
512 KB |
Output is correct |
8 |
Correct |
946 ms |
540 KB |
Output is correct |
9 |
Correct |
606 ms |
512 KB |
Output is correct |
10 |
Correct |
544 ms |
504 KB |
Output is correct |
11 |
Correct |
7 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
596 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
356 ms |
508 KB |
Output is correct |
17 |
Correct |
470 ms |
400 KB |
Output is correct |
18 |
Correct |
449 ms |
528 KB |
Output is correct |
19 |
Correct |
600 ms |
532 KB |
Output is correct |
20 |
Correct |
556 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
610 ms |
644 KB |
Output is correct |
2 |
Correct |
504 ms |
612 KB |
Output is correct |
3 |
Correct |
928 ms |
500 KB |
Output is correct |
4 |
Correct |
620 ms |
516 KB |
Output is correct |
5 |
Correct |
592 ms |
512 KB |
Output is correct |
6 |
Correct |
452 ms |
528 KB |
Output is correct |
7 |
Correct |
466 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
472 KB |
Output is correct |
9 |
Correct |
3 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
470 ms |
516 KB |
Output is correct |
12 |
Correct |
475 ms |
584 KB |
Output is correct |
13 |
Correct |
711 ms |
400 KB |
Output is correct |
14 |
Correct |
581 ms |
528 KB |
Output is correct |
15 |
Correct |
563 ms |
528 KB |
Output is correct |
16 |
Correct |
415 ms |
512 KB |
Output is correct |
17 |
Correct |
518 ms |
516 KB |
Output is correct |
18 |
Correct |
432 ms |
628 KB |
Output is correct |
19 |
Correct |
432 ms |
876 KB |
Output is correct |
20 |
Correct |
480 ms |
512 KB |
Output is correct |
21 |
Correct |
64 ms |
548 KB |
Output is correct |
22 |
Correct |
71 ms |
576 KB |
Output is correct |
23 |
Correct |
95 ms |
708 KB |
Output is correct |
24 |
Correct |
5 ms |
596 KB |
Output is correct |
25 |
Correct |
7 ms |
596 KB |
Output is correct |
26 |
Correct |
5 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
538 ms |
400 KB |
Output is correct |
30 |
Correct |
530 ms |
508 KB |
Output is correct |
31 |
Correct |
516 ms |
508 KB |
Output is correct |
32 |
Correct |
566 ms |
400 KB |
Output is correct |
33 |
Correct |
635 ms |
524 KB |
Output is correct |
34 |
Correct |
352 ms |
528 KB |
Output is correct |
35 |
Correct |
474 ms |
740 KB |
Output is correct |
36 |
Correct |
505 ms |
640 KB |
Output is correct |
37 |
Correct |
517 ms |
768 KB |
Output is correct |
38 |
Correct |
433 ms |
632 KB |
Output is correct |
39 |
Correct |
380 ms |
624 KB |
Output is correct |
40 |
Correct |
434 ms |
756 KB |
Output is correct |
41 |
Correct |
504 ms |
624 KB |
Output is correct |
42 |
Correct |
63 ms |
616 KB |
Output is correct |
43 |
Correct |
122 ms |
712 KB |
Output is correct |
44 |
Correct |
111 ms |
528 KB |
Output is correct |
45 |
Correct |
170 ms |
528 KB |
Output is correct |
46 |
Correct |
332 ms |
564 KB |
Output is correct |
47 |
Correct |
316 ms |
532 KB |
Output is correct |
48 |
Correct |
61 ms |
672 KB |
Output is correct |
49 |
Correct |
62 ms |
704 KB |
Output is correct |