#include "stations.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(),v.end()
#pragma gcc optimize("O3")
#pragma gcc optimize("Ofast")
#pragma gcc optimize("unroll-loops")
using namespace std;
const int INF = 1e9;
const int TMX = 1 << 18;
const long long llINF = 2e18;
const long long mod = 1e9+7;
const long long hashmod = 100003;
const int MAXN = 100000;
const int MAXM = 1000000;
typedef long long ll;
typedef long double ld;
typedef pair <int,int> pi;
typedef pair <ll,ll> pl;
typedef vector <int> vec;
typedef vector <pi> vecpi;
typedef long long ll;
int co,n,k;
vec v[1005];
vec la;
void dfs(int x,int pr,int dep) {
if(dep % 2) la[x] = ++co;
for(int i : v[x]) if(i^pr) dfs(i,x,dep+1);
if(dep % 2 == 0) la[x] = ++co;
}
std::vector<int> label(int N, int K, std::vector<int> u, std::vector<int> u2) {
n = N, k = K;
for(int i = 0;i < n;i++) v[i].clear();
for(int i = 0;i < n-1;i++) v[u[i]].pb(u2[i]), v[u2[i]].pb(u[i]);
la.resize(n,0);
co = 0; dfs(1,-1,1);
return la;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(all(c));
int isin = (s < c[0]), isroot = (s == 1);
int par = -1,m = c.size();
if(isin) {
par = c.back();
m--;
int l = s+1;
for(int i = 0;i < m;i++) {
if(l <= t&&t <= c[i]) return c[i];
l = c[i]+1;
}
return par;
}
else {
par = c[0];
for(int i = 0;i < m-1;i++) c[i] = c[i+1];
m--;
c[m] = s;
for(int i = 0;i < m;i++) {
if(c[i] <= t&&t < c[i+1]) return c[i];
}
return par;
}
}
Compilation message
stations.cpp:7: warning: ignoring #pragma gcc optimize [-Wunknown-pragmas]
7 | #pragma gcc optimize("O3")
|
stations.cpp:8: warning: ignoring #pragma gcc optimize [-Wunknown-pragmas]
8 | #pragma gcc optimize("Ofast")
|
stations.cpp:9: warning: ignoring #pragma gcc optimize [-Wunknown-pragmas]
9 | #pragma gcc optimize("unroll-loops")
|
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:46:28: warning: unused variable 'isroot' [-Wunused-variable]
46 | int isin = (s < c[0]), isroot = (s == 1);
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
536 ms |
992 KB |
Output is correct |
2 |
Correct |
495 ms |
992 KB |
Output is correct |
3 |
Correct |
976 ms |
864 KB |
Output is correct |
4 |
Correct |
819 ms |
952 KB |
Output is correct |
5 |
Correct |
760 ms |
864 KB |
Output is correct |
6 |
Correct |
498 ms |
992 KB |
Output is correct |
7 |
Correct |
455 ms |
1120 KB |
Output is correct |
8 |
Correct |
2 ms |
952 KB |
Output is correct |
9 |
Correct |
6 ms |
952 KB |
Output is correct |
10 |
Correct |
2 ms |
960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
594 ms |
864 KB |
Output is correct |
2 |
Correct |
543 ms |
864 KB |
Output is correct |
3 |
Correct |
1085 ms |
952 KB |
Output is correct |
4 |
Correct |
738 ms |
864 KB |
Output is correct |
5 |
Correct |
658 ms |
736 KB |
Output is correct |
6 |
Correct |
549 ms |
864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
612 ms |
992 KB |
Output is correct |
2 |
Correct |
465 ms |
1068 KB |
Output is correct |
3 |
Correct |
911 ms |
992 KB |
Output is correct |
4 |
Correct |
793 ms |
864 KB |
Output is correct |
5 |
Correct |
584 ms |
864 KB |
Output is correct |
6 |
Correct |
517 ms |
992 KB |
Output is correct |
7 |
Correct |
441 ms |
864 KB |
Output is correct |
8 |
Correct |
3 ms |
864 KB |
Output is correct |
9 |
Correct |
6 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
960 KB |
Output is correct |
11 |
Correct |
620 ms |
780 KB |
Output is correct |
12 |
Correct |
544 ms |
1084 KB |
Output is correct |
13 |
Correct |
498 ms |
1088 KB |
Output is correct |
14 |
Correct |
485 ms |
1108 KB |
Output is correct |
15 |
Correct |
54 ms |
736 KB |
Output is correct |
16 |
Correct |
85 ms |
864 KB |
Output is correct |
17 |
Correct |
136 ms |
1012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
952 ms |
864 KB |
Output is correct |
2 |
Correct |
774 ms |
864 KB |
Output is correct |
3 |
Correct |
729 ms |
896 KB |
Output is correct |
4 |
Correct |
3 ms |
736 KB |
Output is correct |
5 |
Correct |
5 ms |
864 KB |
Output is correct |
6 |
Correct |
2 ms |
952 KB |
Output is correct |
7 |
Correct |
669 ms |
952 KB |
Output is correct |
8 |
Correct |
958 ms |
864 KB |
Output is correct |
9 |
Correct |
670 ms |
992 KB |
Output is correct |
10 |
Correct |
638 ms |
864 KB |
Output is correct |
11 |
Correct |
7 ms |
1024 KB |
Output is correct |
12 |
Correct |
8 ms |
864 KB |
Output is correct |
13 |
Correct |
7 ms |
952 KB |
Output is correct |
14 |
Correct |
5 ms |
864 KB |
Output is correct |
15 |
Correct |
2 ms |
864 KB |
Output is correct |
16 |
Correct |
490 ms |
864 KB |
Output is correct |
17 |
Correct |
501 ms |
864 KB |
Output is correct |
18 |
Correct |
489 ms |
736 KB |
Output is correct |
19 |
Correct |
545 ms |
952 KB |
Output is correct |
20 |
Correct |
527 ms |
864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
549 ms |
1272 KB |
Output is correct |
2 |
Correct |
451 ms |
1000 KB |
Output is correct |
3 |
Correct |
936 ms |
864 KB |
Output is correct |
4 |
Correct |
696 ms |
992 KB |
Output is correct |
5 |
Correct |
674 ms |
864 KB |
Output is correct |
6 |
Correct |
467 ms |
1228 KB |
Output is correct |
7 |
Correct |
506 ms |
864 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
5 ms |
736 KB |
Output is correct |
10 |
Correct |
2 ms |
736 KB |
Output is correct |
11 |
Correct |
510 ms |
736 KB |
Output is correct |
12 |
Correct |
581 ms |
888 KB |
Output is correct |
13 |
Correct |
1039 ms |
896 KB |
Output is correct |
14 |
Correct |
674 ms |
736 KB |
Output is correct |
15 |
Correct |
695 ms |
864 KB |
Output is correct |
16 |
Correct |
514 ms |
864 KB |
Output is correct |
17 |
Correct |
618 ms |
952 KB |
Output is correct |
18 |
Correct |
493 ms |
1088 KB |
Output is correct |
19 |
Correct |
430 ms |
1072 KB |
Output is correct |
20 |
Correct |
480 ms |
736 KB |
Output is correct |
21 |
Correct |
74 ms |
952 KB |
Output is correct |
22 |
Correct |
81 ms |
864 KB |
Output is correct |
23 |
Correct |
134 ms |
864 KB |
Output is correct |
24 |
Correct |
6 ms |
960 KB |
Output is correct |
25 |
Correct |
5 ms |
736 KB |
Output is correct |
26 |
Correct |
5 ms |
736 KB |
Output is correct |
27 |
Correct |
4 ms |
1088 KB |
Output is correct |
28 |
Correct |
1 ms |
952 KB |
Output is correct |
29 |
Correct |
516 ms |
896 KB |
Output is correct |
30 |
Correct |
555 ms |
952 KB |
Output is correct |
31 |
Correct |
555 ms |
864 KB |
Output is correct |
32 |
Correct |
629 ms |
952 KB |
Output is correct |
33 |
Correct |
622 ms |
864 KB |
Output is correct |
34 |
Correct |
334 ms |
1088 KB |
Output is correct |
35 |
Correct |
505 ms |
864 KB |
Output is correct |
36 |
Correct |
562 ms |
1200 KB |
Output is correct |
37 |
Correct |
545 ms |
1004 KB |
Output is correct |
38 |
Correct |
521 ms |
1100 KB |
Output is correct |
39 |
Correct |
455 ms |
1120 KB |
Output is correct |
40 |
Correct |
469 ms |
1116 KB |
Output is correct |
41 |
Correct |
496 ms |
1448 KB |
Output is correct |
42 |
Correct |
89 ms |
736 KB |
Output is correct |
43 |
Correct |
112 ms |
896 KB |
Output is correct |
44 |
Correct |
153 ms |
1140 KB |
Output is correct |
45 |
Correct |
146 ms |
736 KB |
Output is correct |
46 |
Correct |
388 ms |
888 KB |
Output is correct |
47 |
Correct |
429 ms |
992 KB |
Output is correct |
48 |
Correct |
70 ms |
900 KB |
Output is correct |
49 |
Correct |
55 ms |
1028 KB |
Output is correct |