#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<int> labels;
vector<vector<int>> graph;
vector<int> sz;
void dfs1(int n,int p){//calc sizes
sz[n] = 1;
for(int adj : graph[n])
{
if(adj == p) continue;
dfs1(adj, n);
sz[n] += sz[adj];
}
}
int counter;
void name_subtree(int n, int p){
labels[n] =sz[n] + (counter << 10) ;
counter++;
for(int adj : graph[n]){
if(adj == p)
continue;
name_subtree(adj, n);
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
counter = 0;
sz.clear();
labels.clear();
graph.clear();
sz.assign(n, 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]);
}
int root = 0;
dfs1(0,-1);
//for(int i =0; i<n; i++) cout <<i<<": "<< sz[i]<<endl;
name_subtree(root, -1);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
int startind = ( s>> 10);
int targetind = (t>>10);
for(int adj : c){
int adjind = (adj >> 10);
if(adjind < startind) continue;
//cout << s <<"->"<<t<<": "<<adj<<", "<<sz[adj]<<endl;
if(adjind<= targetind and targetind <= adjind + adj - (adjind<<10) -1){
//cout << startind<<"->"<<targetind<<": "<<adjind<<", "<<adj - (adjind<<10) -1 <<endl;
return adj;
}
}
return c[0];
}
/************/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
404 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=6148 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
276 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1535 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
412 KB |
Invalid labels (values out of range). scenario=1, k=1000000, vertex=67, label=1006606 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1037 ms |
468 KB |
Output is correct |
2 |
Correct |
857 ms |
400 KB |
Output is correct |
3 |
Correct |
947 ms |
472 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
7 ms |
476 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
912 ms |
400 KB |
Output is correct |
8 |
Correct |
1376 ms |
400 KB |
Output is correct |
9 |
Correct |
850 ms |
488 KB |
Output is correct |
10 |
Correct |
596 ms |
400 KB |
Output is correct |
11 |
Correct |
7 ms |
464 KB |
Output is correct |
12 |
Correct |
7 ms |
476 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
464 KB |
Output is correct |
16 |
Correct |
733 ms |
400 KB |
Output is correct |
17 |
Correct |
788 ms |
400 KB |
Output is correct |
18 |
Correct |
760 ms |
488 KB |
Output is correct |
19 |
Correct |
585 ms |
488 KB |
Output is correct |
20 |
Correct |
490 ms |
400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
706 ms |
608 KB |
Partially correct |
2 |
Partially correct |
453 ms |
608 KB |
Partially correct |
3 |
Partially correct |
1321 ms |
492 KB |
Partially correct |
4 |
Partially correct |
838 ms |
488 KB |
Partially correct |
5 |
Partially correct |
641 ms |
400 KB |
Partially correct |
6 |
Partially correct |
817 ms |
620 KB |
Partially correct |
7 |
Partially correct |
665 ms |
480 KB |
Partially correct |
8 |
Partially correct |
4 ms |
448 KB |
Partially correct |
9 |
Partially correct |
7 ms |
468 KB |
Partially correct |
10 |
Partially correct |
2 ms |
468 KB |
Partially correct |
11 |
Partially correct |
672 ms |
604 KB |
Partially correct |
12 |
Partially correct |
916 ms |
480 KB |
Partially correct |
13 |
Partially correct |
871 ms |
472 KB |
Partially correct |
14 |
Partially correct |
905 ms |
400 KB |
Partially correct |
15 |
Partially correct |
757 ms |
400 KB |
Partially correct |
16 |
Partially correct |
639 ms |
480 KB |
Partially correct |
17 |
Partially correct |
592 ms |
400 KB |
Partially correct |
18 |
Partially correct |
652 ms |
692 KB |
Partially correct |
19 |
Partially correct |
618 ms |
608 KB |
Partially correct |
20 |
Partially correct |
472 ms |
492 KB |
Partially correct |
21 |
Partially correct |
70 ms |
400 KB |
Partially correct |
22 |
Partially correct |
109 ms |
528 KB |
Partially correct |
23 |
Partially correct |
155 ms |
528 KB |
Partially correct |
24 |
Partially correct |
6 ms |
528 KB |
Partially correct |
25 |
Partially correct |
5 ms |
468 KB |
Partially correct |
26 |
Partially correct |
7 ms |
468 KB |
Partially correct |
27 |
Partially correct |
4 ms |
468 KB |
Partially correct |
28 |
Partially correct |
3 ms |
476 KB |
Partially correct |
29 |
Partially correct |
773 ms |
492 KB |
Partially correct |
30 |
Partially correct |
688 ms |
400 KB |
Partially correct |
31 |
Partially correct |
652 ms |
400 KB |
Partially correct |
32 |
Partially correct |
549 ms |
492 KB |
Partially correct |
33 |
Partially correct |
512 ms |
400 KB |
Partially correct |
34 |
Partially correct |
365 ms |
624 KB |
Partially correct |
35 |
Partially correct |
512 ms |
656 KB |
Partially correct |
36 |
Partially correct |
667 ms |
724 KB |
Partially correct |
37 |
Partially correct |
525 ms |
680 KB |
Partially correct |
38 |
Partially correct |
628 ms |
660 KB |
Partially correct |
39 |
Partially correct |
570 ms |
680 KB |
Partially correct |
40 |
Partially correct |
642 ms |
616 KB |
Partially correct |
41 |
Partially correct |
597 ms |
612 KB |
Partially correct |
42 |
Partially correct |
86 ms |
532 KB |
Partially correct |
43 |
Partially correct |
164 ms |
492 KB |
Partially correct |
44 |
Partially correct |
207 ms |
588 KB |
Partially correct |
45 |
Partially correct |
179 ms |
488 KB |
Partially correct |
46 |
Partially correct |
370 ms |
528 KB |
Partially correct |
47 |
Partially correct |
391 ms |
528 KB |
Partially correct |
48 |
Partially correct |
115 ms |
528 KB |
Partially correct |
49 |
Partially correct |
85 ms |
584 KB |
Partially correct |