#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
vector<vector<int>> adj;
vector<int> lvl, lbl;
int currentLabel;
void DFS(int index, int last)
{
lvl[index] = lvl[last] + 1;
if (lvl[index]%2==0)
{
// Maximum node
lbl[index] = currentLabel--;
}
for (auto node : adj[index])
{
if (node == last) continue;
DFS(node, index);
}
if (lvl[index]%2)
{
// Minimum node
lbl[index] = currentLabel--;
}
}
vector<int> label(int N, int K, vector<int> U, vector<int> V)
{
// Alternate labeling (max and min subtree size)
adj = vector<vector<int>>(N);
lvl = vector<int>(N);
lbl = vector<int>(N);
for (int i = 0; i < N - 1; i++)
{
adj[U[i]].push_back(V[i]);
adj[V[i]].push_back(U[i]);
}
currentLabel = N - 1;
DFS(0, 0);
return lbl;
}
int find_next_station(int S, int T, vector<int> C)
{
if (C.size()==1)
return C[0];
if (S > C[0])
{
// Max node
// Find largest smaller than T
if (T > S || T < C[1])
return C[0];
int l = 1, r = C.size() - 1;
while (l<r)
{
int c = (l+r+1)/2;
if (C[c] <= T)
l = c;
else
r = c - 1;
}
return C[l];
}
else
{
// Min node
if (T < S || T > C[C.size()-2])
return C.back();
// Find smallest larger than T
int l = 0, r = C.size() - 2;
while (l<r)
{
int c = (l+r)/2;
if (C[c] >= T)
r = c;
else
l = c + 1;
}
return C[l];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
936 KB |
Output is correct |
2 |
Correct |
261 ms |
944 KB |
Output is correct |
3 |
Correct |
559 ms |
684 KB |
Output is correct |
4 |
Correct |
447 ms |
684 KB |
Output is correct |
5 |
Correct |
376 ms |
684 KB |
Output is correct |
6 |
Correct |
295 ms |
928 KB |
Output is correct |
7 |
Correct |
290 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
1272 KB |
Output is correct |
9 |
Correct |
2 ms |
764 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
290 ms |
896 KB |
Output is correct |
2 |
Correct |
324 ms |
792 KB |
Output is correct |
3 |
Correct |
556 ms |
684 KB |
Output is correct |
4 |
Correct |
431 ms |
684 KB |
Output is correct |
5 |
Correct |
404 ms |
888 KB |
Output is correct |
6 |
Correct |
275 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
358 ms |
924 KB |
Output is correct |
2 |
Correct |
338 ms |
940 KB |
Output is correct |
3 |
Correct |
581 ms |
684 KB |
Output is correct |
4 |
Correct |
390 ms |
684 KB |
Output is correct |
5 |
Correct |
404 ms |
692 KB |
Output is correct |
6 |
Correct |
284 ms |
900 KB |
Output is correct |
7 |
Correct |
288 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
764 KB |
Output is correct |
11 |
Correct |
414 ms |
684 KB |
Output is correct |
12 |
Correct |
305 ms |
956 KB |
Output is correct |
13 |
Correct |
331 ms |
1308 KB |
Output is correct |
14 |
Correct |
290 ms |
684 KB |
Output is correct |
15 |
Correct |
26 ms |
768 KB |
Output is correct |
16 |
Correct |
37 ms |
928 KB |
Output is correct |
17 |
Correct |
53 ms |
892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
594 ms |
684 KB |
Output is correct |
2 |
Correct |
444 ms |
684 KB |
Output is correct |
3 |
Correct |
420 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
0 ms |
768 KB |
Output is correct |
7 |
Correct |
360 ms |
684 KB |
Output is correct |
8 |
Correct |
516 ms |
684 KB |
Output is correct |
9 |
Correct |
456 ms |
684 KB |
Output is correct |
10 |
Correct |
436 ms |
684 KB |
Output is correct |
11 |
Correct |
2 ms |
764 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
3 ms |
776 KB |
Output is correct |
15 |
Correct |
0 ms |
768 KB |
Output is correct |
16 |
Correct |
319 ms |
684 KB |
Output is correct |
17 |
Correct |
321 ms |
684 KB |
Output is correct |
18 |
Correct |
345 ms |
684 KB |
Output is correct |
19 |
Correct |
328 ms |
684 KB |
Output is correct |
20 |
Correct |
310 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
325 ms |
924 KB |
Output is correct |
2 |
Correct |
279 ms |
964 KB |
Output is correct |
3 |
Correct |
567 ms |
684 KB |
Output is correct |
4 |
Correct |
414 ms |
684 KB |
Output is correct |
5 |
Correct |
371 ms |
684 KB |
Output is correct |
6 |
Correct |
298 ms |
944 KB |
Output is correct |
7 |
Correct |
308 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
764 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
298 ms |
900 KB |
Output is correct |
12 |
Correct |
377 ms |
832 KB |
Output is correct |
13 |
Correct |
534 ms |
684 KB |
Output is correct |
14 |
Correct |
469 ms |
860 KB |
Output is correct |
15 |
Correct |
388 ms |
884 KB |
Output is correct |
16 |
Correct |
281 ms |
684 KB |
Output is correct |
17 |
Correct |
351 ms |
684 KB |
Output is correct |
18 |
Correct |
266 ms |
1176 KB |
Output is correct |
19 |
Correct |
268 ms |
1528 KB |
Output is correct |
20 |
Correct |
298 ms |
684 KB |
Output is correct |
21 |
Correct |
32 ms |
768 KB |
Output is correct |
22 |
Correct |
38 ms |
1184 KB |
Output is correct |
23 |
Correct |
62 ms |
864 KB |
Output is correct |
24 |
Correct |
4 ms |
768 KB |
Output is correct |
25 |
Correct |
3 ms |
764 KB |
Output is correct |
26 |
Correct |
2 ms |
768 KB |
Output is correct |
27 |
Correct |
3 ms |
768 KB |
Output is correct |
28 |
Correct |
0 ms |
768 KB |
Output is correct |
29 |
Correct |
328 ms |
684 KB |
Output is correct |
30 |
Correct |
365 ms |
684 KB |
Output is correct |
31 |
Correct |
314 ms |
684 KB |
Output is correct |
32 |
Correct |
332 ms |
684 KB |
Output is correct |
33 |
Correct |
326 ms |
684 KB |
Output is correct |
34 |
Correct |
201 ms |
936 KB |
Output is correct |
35 |
Correct |
251 ms |
1272 KB |
Output is correct |
36 |
Correct |
298 ms |
1016 KB |
Output is correct |
37 |
Correct |
293 ms |
1260 KB |
Output is correct |
38 |
Correct |
289 ms |
1176 KB |
Output is correct |
39 |
Correct |
279 ms |
1012 KB |
Output is correct |
40 |
Correct |
289 ms |
1008 KB |
Output is correct |
41 |
Correct |
324 ms |
1236 KB |
Output is correct |
42 |
Correct |
34 ms |
928 KB |
Output is correct |
43 |
Correct |
58 ms |
916 KB |
Output is correct |
44 |
Correct |
90 ms |
884 KB |
Output is correct |
45 |
Correct |
96 ms |
924 KB |
Output is correct |
46 |
Correct |
187 ms |
852 KB |
Output is correct |
47 |
Correct |
202 ms |
940 KB |
Output is correct |
48 |
Correct |
33 ms |
1496 KB |
Output is correct |
49 |
Correct |
41 ms |
1424 KB |
Output is correct |