#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pi pair<int,int>
vector<int> labels;
vector<vector<int>> graph;
vector<pi> ord;
int cnt = 0;
void dfs1(int n,int p, bool first){//calc sizes
if(first)
labels[n] = cnt++;
//ord[n].first = cnt++;
for(int adj : graph[n])
{
if(adj == p) continue;
dfs1(adj, n, !first);
}
if(!first)
labels[n ] = cnt++;
//ord[n].second = cnt++;
}
void name_subtree(int n, int p, bool first){
if(first)
labels[n] = ord[n].first;
else
labels[n] = ord[n].second;
for(int adj : graph[n]){
if(adj == p)
continue;
name_subtree(adj, n, !first);
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
cnt = 0;
ord.clear();
labels.clear();
graph.clear();
ord.assign(n, {0,0});
labels.assign(n, 0);
graph.assign( n, vector<int>());
for (int i = 0; i < n - 1; i++) {
graph[u[i]].pb(v[i]);
graph[v[i]].pb(u[i]);
}
dfs1(0,-1, 1);
int root = 0;
//for(int i =0; i<n; i++) cout <<i<<": "<< ord[i].first<<", "<<ord[i].second<<endl;
//name_subtree(root, -1, 1);
//for(int i =0; i<n; i++) cout <<i<<": "<< labels[i]<<endl;
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if(c.size() == 1) return c[0];
bool isfirst = c[0] > s;
if(isfirst){
if(t < s) return c[c.size() - 1];
for(int adj : c){
if(t <= adj) return adj;
}
return c[c.size()-1] ;
}
else{
reverse(c.begin(), c.end());
if( t > s) return c[c.size()-1];
for(int adj : c)
if(t >= adj)
return adj;
return c[c.size()-1];
}
}
/************/
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:58:6: warning: unused variable 'root' [-Wunused-variable]
58 | int root = 0;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
546 ms |
616 KB |
Output is correct |
2 |
Correct |
506 ms |
664 KB |
Output is correct |
3 |
Correct |
863 ms |
524 KB |
Output is correct |
4 |
Correct |
695 ms |
468 KB |
Output is correct |
5 |
Correct |
611 ms |
400 KB |
Output is correct |
6 |
Correct |
477 ms |
612 KB |
Output is correct |
7 |
Correct |
424 ms |
612 KB |
Output is correct |
8 |
Correct |
2 ms |
540 KB |
Output is correct |
9 |
Correct |
4 ms |
464 KB |
Output is correct |
10 |
Correct |
2 ms |
488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
456 ms |
608 KB |
Output is correct |
2 |
Correct |
610 ms |
520 KB |
Output is correct |
3 |
Correct |
930 ms |
508 KB |
Output is correct |
4 |
Correct |
649 ms |
468 KB |
Output is correct |
5 |
Correct |
656 ms |
472 KB |
Output is correct |
6 |
Correct |
482 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
505 ms |
644 KB |
Output is correct |
2 |
Correct |
445 ms |
652 KB |
Output is correct |
3 |
Correct |
861 ms |
488 KB |
Output is correct |
4 |
Correct |
661 ms |
492 KB |
Output is correct |
5 |
Correct |
571 ms |
484 KB |
Output is correct |
6 |
Correct |
459 ms |
612 KB |
Output is correct |
7 |
Correct |
411 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
472 KB |
Output is correct |
11 |
Correct |
583 ms |
400 KB |
Output is correct |
12 |
Correct |
508 ms |
696 KB |
Output is correct |
13 |
Correct |
520 ms |
796 KB |
Output is correct |
14 |
Correct |
464 ms |
496 KB |
Output is correct |
15 |
Correct |
58 ms |
420 KB |
Output is correct |
16 |
Correct |
80 ms |
552 KB |
Output is correct |
17 |
Correct |
99 ms |
644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
930 ms |
472 KB |
Output is correct |
2 |
Correct |
701 ms |
404 KB |
Output is correct |
3 |
Correct |
636 ms |
400 KB |
Output is correct |
4 |
Correct |
3 ms |
584 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
540 KB |
Output is correct |
7 |
Correct |
552 ms |
400 KB |
Output is correct |
8 |
Correct |
861 ms |
464 KB |
Output is correct |
9 |
Correct |
662 ms |
472 KB |
Output is correct |
10 |
Correct |
618 ms |
400 KB |
Output is correct |
11 |
Correct |
7 ms |
540 KB |
Output is correct |
12 |
Correct |
9 ms |
468 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
522 ms |
400 KB |
Output is correct |
17 |
Correct |
573 ms |
400 KB |
Output is correct |
18 |
Correct |
526 ms |
484 KB |
Output is correct |
19 |
Correct |
565 ms |
488 KB |
Output is correct |
20 |
Correct |
521 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
552 ms |
680 KB |
Output is correct |
2 |
Correct |
493 ms |
604 KB |
Output is correct |
3 |
Correct |
868 ms |
468 KB |
Output is correct |
4 |
Correct |
645 ms |
488 KB |
Output is correct |
5 |
Correct |
626 ms |
488 KB |
Output is correct |
6 |
Correct |
469 ms |
632 KB |
Output is correct |
7 |
Correct |
461 ms |
616 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
420 KB |
Output is correct |
11 |
Correct |
479 ms |
556 KB |
Output is correct |
12 |
Correct |
573 ms |
484 KB |
Output is correct |
13 |
Correct |
1009 ms |
520 KB |
Output is correct |
14 |
Correct |
688 ms |
400 KB |
Output is correct |
15 |
Correct |
650 ms |
520 KB |
Output is correct |
16 |
Correct |
451 ms |
524 KB |
Output is correct |
17 |
Correct |
642 ms |
400 KB |
Output is correct |
18 |
Correct |
509 ms |
684 KB |
Output is correct |
19 |
Correct |
504 ms |
684 KB |
Output is correct |
20 |
Correct |
445 ms |
528 KB |
Output is correct |
21 |
Correct |
58 ms |
416 KB |
Output is correct |
22 |
Correct |
77 ms |
528 KB |
Output is correct |
23 |
Correct |
115 ms |
528 KB |
Output is correct |
24 |
Correct |
4 ms |
468 KB |
Output is correct |
25 |
Correct |
7 ms |
420 KB |
Output is correct |
26 |
Correct |
4 ms |
400 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
593 ms |
528 KB |
Output is correct |
30 |
Correct |
560 ms |
476 KB |
Output is correct |
31 |
Correct |
526 ms |
480 KB |
Output is correct |
32 |
Correct |
598 ms |
400 KB |
Output is correct |
33 |
Correct |
507 ms |
472 KB |
Output is correct |
34 |
Correct |
328 ms |
620 KB |
Output is correct |
35 |
Correct |
456 ms |
668 KB |
Output is correct |
36 |
Correct |
449 ms |
696 KB |
Output is correct |
37 |
Correct |
479 ms |
696 KB |
Output is correct |
38 |
Correct |
521 ms |
692 KB |
Output is correct |
39 |
Correct |
443 ms |
688 KB |
Output is correct |
40 |
Correct |
455 ms |
676 KB |
Output is correct |
41 |
Correct |
466 ms |
556 KB |
Output is correct |
42 |
Correct |
65 ms |
528 KB |
Output is correct |
43 |
Correct |
114 ms |
592 KB |
Output is correct |
44 |
Correct |
153 ms |
528 KB |
Output is correct |
45 |
Correct |
171 ms |
572 KB |
Output is correct |
46 |
Correct |
342 ms |
484 KB |
Output is correct |
47 |
Correct |
316 ms |
484 KB |
Output is correct |
48 |
Correct |
64 ms |
528 KB |
Output is correct |
49 |
Correct |
69 ms |
648 KB |
Output is correct |