#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
matrix<int> g(n);
for(int i = 0; i < n-1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
int timer = -1;
vector<int> labels(n);
auto dfs =[&](int id, int last, int height, auto dfs)->void{
if(!height)
labels[id] = ++timer;
for(int i : g[id]){
if(i!=last)
dfs(i,id,height^1,dfs);
}
if(height)
labels[id] = ++timer;
};
dfs(0,0,0,dfs);
return labels;
}
bool intersect(int l, int r, int v){
if(r < l)
swap(l,r);
return l <= v && v <= r;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c[0] < s)
reverse(all(c));
int ini = 0, fim = int(c.size())-1;
while(ini!=fim){
int m = (ini+fim)>>1;
if(intersect(s,c[m],t))
fim = m;
else ini = m+1;
}
return c[ini];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
510 ms |
508 KB |
Output is correct |
2 |
Correct |
400 ms |
496 KB |
Output is correct |
3 |
Correct |
809 ms |
420 KB |
Output is correct |
4 |
Correct |
596 ms |
504 KB |
Output is correct |
5 |
Correct |
574 ms |
416 KB |
Output is correct |
6 |
Correct |
402 ms |
548 KB |
Output is correct |
7 |
Correct |
447 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
447 ms |
544 KB |
Output is correct |
2 |
Correct |
526 ms |
508 KB |
Output is correct |
3 |
Correct |
852 ms |
420 KB |
Output is correct |
4 |
Correct |
655 ms |
420 KB |
Output is correct |
5 |
Correct |
641 ms |
500 KB |
Output is correct |
6 |
Correct |
479 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
475 ms |
544 KB |
Output is correct |
2 |
Correct |
515 ms |
544 KB |
Output is correct |
3 |
Correct |
867 ms |
416 KB |
Output is correct |
4 |
Correct |
597 ms |
576 KB |
Output is correct |
5 |
Correct |
438 ms |
420 KB |
Output is correct |
6 |
Correct |
380 ms |
540 KB |
Output is correct |
7 |
Correct |
483 ms |
500 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
0 ms |
492 KB |
Output is correct |
11 |
Correct |
591 ms |
416 KB |
Output is correct |
12 |
Correct |
388 ms |
580 KB |
Output is correct |
13 |
Correct |
489 ms |
864 KB |
Output is correct |
14 |
Correct |
463 ms |
548 KB |
Output is correct |
15 |
Correct |
54 ms |
492 KB |
Output is correct |
16 |
Correct |
59 ms |
500 KB |
Output is correct |
17 |
Correct |
74 ms |
568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
761 ms |
488 KB |
Output is correct |
2 |
Correct |
626 ms |
416 KB |
Output is correct |
3 |
Correct |
458 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
500 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
473 ms |
416 KB |
Output is correct |
8 |
Correct |
806 ms |
420 KB |
Output is correct |
9 |
Correct |
589 ms |
416 KB |
Output is correct |
10 |
Correct |
578 ms |
416 KB |
Output is correct |
11 |
Correct |
3 ms |
500 KB |
Output is correct |
12 |
Correct |
5 ms |
500 KB |
Output is correct |
13 |
Correct |
3 ms |
500 KB |
Output is correct |
14 |
Correct |
4 ms |
500 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
483 ms |
500 KB |
Output is correct |
17 |
Correct |
465 ms |
420 KB |
Output is correct |
18 |
Correct |
389 ms |
504 KB |
Output is correct |
19 |
Correct |
593 ms |
464 KB |
Output is correct |
20 |
Correct |
507 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
617 ms |
504 KB |
Output is correct |
2 |
Correct |
471 ms |
508 KB |
Output is correct |
3 |
Correct |
809 ms |
416 KB |
Output is correct |
4 |
Correct |
661 ms |
416 KB |
Output is correct |
5 |
Correct |
549 ms |
420 KB |
Output is correct |
6 |
Correct |
473 ms |
544 KB |
Output is correct |
7 |
Correct |
430 ms |
544 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
500 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
446 ms |
508 KB |
Output is correct |
12 |
Correct |
438 ms |
564 KB |
Output is correct |
13 |
Correct |
863 ms |
420 KB |
Output is correct |
14 |
Correct |
640 ms |
416 KB |
Output is correct |
15 |
Correct |
657 ms |
420 KB |
Output is correct |
16 |
Correct |
451 ms |
544 KB |
Output is correct |
17 |
Correct |
601 ms |
504 KB |
Output is correct |
18 |
Correct |
445 ms |
636 KB |
Output is correct |
19 |
Correct |
463 ms |
700 KB |
Output is correct |
20 |
Correct |
475 ms |
500 KB |
Output is correct |
21 |
Correct |
79 ms |
420 KB |
Output is correct |
22 |
Correct |
69 ms |
544 KB |
Output is correct |
23 |
Correct |
88 ms |
544 KB |
Output is correct |
24 |
Correct |
6 ms |
500 KB |
Output is correct |
25 |
Correct |
5 ms |
492 KB |
Output is correct |
26 |
Correct |
4 ms |
492 KB |
Output is correct |
27 |
Correct |
4 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
539 ms |
504 KB |
Output is correct |
30 |
Correct |
448 ms |
508 KB |
Output is correct |
31 |
Correct |
566 ms |
568 KB |
Output is correct |
32 |
Correct |
470 ms |
500 KB |
Output is correct |
33 |
Correct |
593 ms |
508 KB |
Output is correct |
34 |
Correct |
252 ms |
548 KB |
Output is correct |
35 |
Correct |
431 ms |
700 KB |
Output is correct |
36 |
Correct |
467 ms |
716 KB |
Output is correct |
37 |
Correct |
468 ms |
580 KB |
Output is correct |
38 |
Correct |
369 ms |
624 KB |
Output is correct |
39 |
Correct |
424 ms |
588 KB |
Output is correct |
40 |
Correct |
439 ms |
668 KB |
Output is correct |
41 |
Correct |
404 ms |
628 KB |
Output is correct |
42 |
Correct |
62 ms |
572 KB |
Output is correct |
43 |
Correct |
116 ms |
556 KB |
Output is correct |
44 |
Correct |
120 ms |
504 KB |
Output is correct |
45 |
Correct |
146 ms |
544 KB |
Output is correct |
46 |
Correct |
277 ms |
512 KB |
Output is correct |
47 |
Correct |
348 ms |
544 KB |
Output is correct |
48 |
Correct |
49 ms |
640 KB |
Output is correct |
49 |
Correct |
59 ms |
500 KB |
Output is correct |