#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define x first
#define y second
vector<int> labels;
vector<vector<int>> g;
int tme;
void dfs1(int i,int f=0,int t=0){
if(t==0){
labels[i]=++tme*2;
}
for(auto u:g[i]){
if(u!=f){
dfs1(u,i,(t+1)%2);
}
}
if(t==1){
labels[i]=++tme*2+1;
}
}
// void dfs1(int i, int f=0){
// int tin=++tme;
// for(auto u:g[i]){
// if(u!=f){
// dfs1(u,i);
// }
// }
// int tout=tme;
// labels[i]=tin*1000+tout;
// }
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
tme=-1;
labels.assign(n,-1);
g.assign(n,vector<int>());
for(int i=0; i<n-1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs1(0);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
int r=s%2;
s/=2;
vector<pair<ii,int>> cld;
int f=-1;
if(r==0){
int prev=s;
for(auto i:c){
int k=i/2;
cld.emplace_back(ii(prev+1,k),i);
prev=k;
}
if(s!=0){
f=cld.back().y;
cld.pop_back();
}
}
else{
f=c[0];
for(int j=1; j<c.size(); j++){
int i=c[j];
int k=i/2;
if(!cld.empty())
cld.back().x.y=k-1;
cld.emplace_back(ii(k,-1),i);
}
if(!cld.empty()){
cld.back().x.y=s;
}
}
t/=2;
for(auto i:cld){
if(i.x.x<=t&&i.x.y>=t){
return i.y;
}
}
return f;
}
/*
1
5 100
0 1
1 2
1 3
2 4
3
0 1 2
1 2 2
1 4 2*/
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:68:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int j=1; j<c.size(); j++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
452 KB |
Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1991 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
400 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1023 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
527 ms |
624 KB |
Output is correct |
2 |
Correct |
471 ms |
628 KB |
Output is correct |
3 |
Correct |
856 ms |
404 KB |
Output is correct |
4 |
Correct |
705 ms |
488 KB |
Output is correct |
5 |
Correct |
600 ms |
400 KB |
Output is correct |
6 |
Correct |
458 ms |
600 KB |
Output is correct |
7 |
Correct |
505 ms |
616 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 |
468 KB |
Output is correct |
11 |
Correct |
578 ms |
400 KB |
Output is correct |
12 |
Correct |
481 ms |
596 KB |
Output is correct |
13 |
Correct |
472 ms |
520 KB |
Output is correct |
14 |
Correct |
478 ms |
528 KB |
Output is correct |
15 |
Correct |
55 ms |
472 KB |
Output is correct |
16 |
Correct |
68 ms |
540 KB |
Output is correct |
17 |
Correct |
114 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
837 ms |
484 KB |
Output is correct |
2 |
Correct |
672 ms |
400 KB |
Output is correct |
3 |
Correct |
605 ms |
400 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
611 ms |
488 KB |
Output is correct |
8 |
Correct |
861 ms |
468 KB |
Output is correct |
9 |
Correct |
707 ms |
480 KB |
Output is correct |
10 |
Correct |
527 ms |
400 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
6 ms |
468 KB |
Output is correct |
13 |
Correct |
5 ms |
472 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
520 ms |
492 KB |
Output is correct |
17 |
Correct |
462 ms |
400 KB |
Output is correct |
18 |
Correct |
503 ms |
400 KB |
Output is correct |
19 |
Correct |
526 ms |
484 KB |
Output is correct |
20 |
Correct |
584 ms |
400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
492 ms |
608 KB |
Partially correct |
2 |
Partially correct |
468 ms |
608 KB |
Partially correct |
3 |
Correct |
808 ms |
540 KB |
Output is correct |
4 |
Correct |
642 ms |
488 KB |
Output is correct |
5 |
Correct |
536 ms |
400 KB |
Output is correct |
6 |
Partially correct |
494 ms |
604 KB |
Partially correct |
7 |
Partially correct |
476 ms |
476 KB |
Partially correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
464 KB |
Output is correct |
11 |
Partially correct |
453 ms |
528 KB |
Partially correct |
12 |
Partially correct |
502 ms |
520 KB |
Partially correct |
13 |
Correct |
870 ms |
476 KB |
Output is correct |
14 |
Correct |
650 ms |
400 KB |
Output is correct |
15 |
Correct |
577 ms |
492 KB |
Output is correct |
16 |
Partially correct |
455 ms |
488 KB |
Partially correct |
17 |
Correct |
580 ms |
400 KB |
Output is correct |
18 |
Partially correct |
486 ms |
696 KB |
Partially correct |
19 |
Partially correct |
452 ms |
692 KB |
Partially correct |
20 |
Partially correct |
443 ms |
484 KB |
Partially correct |
21 |
Correct |
67 ms |
400 KB |
Output is correct |
22 |
Partially correct |
74 ms |
528 KB |
Partially correct |
23 |
Partially correct |
99 ms |
572 KB |
Partially correct |
24 |
Correct |
5 ms |
524 KB |
Output is correct |
25 |
Correct |
7 ms |
468 KB |
Output is correct |
26 |
Correct |
5 ms |
400 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
476 KB |
Output is correct |
29 |
Correct |
526 ms |
532 KB |
Output is correct |
30 |
Correct |
472 ms |
400 KB |
Output is correct |
31 |
Correct |
525 ms |
528 KB |
Output is correct |
32 |
Correct |
513 ms |
400 KB |
Output is correct |
33 |
Correct |
486 ms |
488 KB |
Output is correct |
34 |
Partially correct |
313 ms |
612 KB |
Partially correct |
35 |
Partially correct |
456 ms |
720 KB |
Partially correct |
36 |
Partially correct |
445 ms |
736 KB |
Partially correct |
37 |
Partially correct |
463 ms |
700 KB |
Partially correct |
38 |
Partially correct |
424 ms |
712 KB |
Partially correct |
39 |
Partially correct |
475 ms |
840 KB |
Partially correct |
40 |
Partially correct |
459 ms |
780 KB |
Partially correct |
41 |
Partially correct |
454 ms |
700 KB |
Partially correct |
42 |
Partially correct |
65 ms |
548 KB |
Partially correct |
43 |
Partially correct |
108 ms |
584 KB |
Partially correct |
44 |
Partially correct |
132 ms |
528 KB |
Partially correct |
45 |
Partially correct |
173 ms |
528 KB |
Partially correct |
46 |
Partially correct |
307 ms |
528 KB |
Partially correct |
47 |
Partially correct |
320 ms |
556 KB |
Partially correct |
48 |
Partially correct |
62 ms |
548 KB |
Partially correct |
49 |
Partially correct |
61 ms |
716 KB |
Partially correct |