#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int N=1e3+100;
const int M=1e3;
vector<int> ma[N];
int tin[N],tout[N],timer=-1;
void dfs(int v, int p)
{
tin[v] = ++timer; // n
for (auto u:ma[v]) {
if (u != p)
dfs(u, v);
}
tout[v] = timer; // n
}
bool is_ancestor(int u, int v)
{
if(u==0)
return 1;
if(v==0)
return 0;
int tn=u/M;
int tot=u%M + tn;
int tn1=v/M;
int tot1=v%M + tn1;
return tn <= tn1 && tot >= tot1;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
timer=-1;
for(int i=0;i<(n);i++)ma[i].clear();
vector<int> labels(n,0);
for(int i=0;i<(n-1);i++)
{
ma[u[i]].push_back(v[i]);
ma[v[i]].push_back(u[i]);
}
dfs(0,-1);
// tout[i] >= tin[i]
// tout[i]-tin[i] == sz[i]
// 1<= sz[i] <=n
for(int i=0;i<n;i++)
labels[i]=((tin[i]-1)*M)+(tout[i]-tin[i]+1);
labels[0]=0;
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(is_ancestor(s,t))
{
for(auto k:c)
{
if(is_ancestor(s,k) and is_ancestor(k,t)){
return k;
}
}
}
for(auto k:c)
if(is_ancestor(k,s))
return k;
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=5004 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
344 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=2, label=511484 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
684 KB |
Output is correct |
2 |
Correct |
308 ms |
684 KB |
Output is correct |
3 |
Correct |
613 ms |
684 KB |
Output is correct |
4 |
Correct |
498 ms |
684 KB |
Output is correct |
5 |
Correct |
411 ms |
684 KB |
Output is correct |
6 |
Correct |
308 ms |
684 KB |
Output is correct |
7 |
Correct |
300 ms |
932 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
11 |
Correct |
410 ms |
936 KB |
Output is correct |
12 |
Correct |
328 ms |
932 KB |
Output is correct |
13 |
Correct |
330 ms |
936 KB |
Output is correct |
14 |
Correct |
331 ms |
684 KB |
Output is correct |
15 |
Correct |
29 ms |
768 KB |
Output is correct |
16 |
Correct |
48 ms |
768 KB |
Output is correct |
17 |
Correct |
54 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
616 ms |
684 KB |
Output is correct |
2 |
Correct |
458 ms |
684 KB |
Output is correct |
3 |
Correct |
403 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
948 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
361 ms |
968 KB |
Output is correct |
8 |
Correct |
620 ms |
684 KB |
Output is correct |
9 |
Correct |
467 ms |
684 KB |
Output is correct |
10 |
Correct |
389 ms |
684 KB |
Output is correct |
11 |
Correct |
3 ms |
764 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
13 |
Correct |
3 ms |
764 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
0 ms |
768 KB |
Output is correct |
16 |
Correct |
370 ms |
684 KB |
Output is correct |
17 |
Correct |
368 ms |
684 KB |
Output is correct |
18 |
Correct |
349 ms |
684 KB |
Output is correct |
19 |
Correct |
322 ms |
688 KB |
Output is correct |
20 |
Correct |
350 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
405 ms |
684 KB |
Partially correct |
2 |
Partially correct |
293 ms |
696 KB |
Partially correct |
3 |
Correct |
649 ms |
684 KB |
Output is correct |
4 |
Partially correct |
493 ms |
684 KB |
Partially correct |
5 |
Partially correct |
419 ms |
684 KB |
Partially correct |
6 |
Partially correct |
293 ms |
684 KB |
Partially correct |
7 |
Partially correct |
337 ms |
684 KB |
Partially correct |
8 |
Partially correct |
1 ms |
764 KB |
Partially correct |
9 |
Partially correct |
2 ms |
768 KB |
Partially correct |
10 |
Partially correct |
1 ms |
768 KB |
Partially correct |
11 |
Partially correct |
316 ms |
684 KB |
Partially correct |
12 |
Partially correct |
371 ms |
684 KB |
Partially correct |
13 |
Correct |
601 ms |
684 KB |
Output is correct |
14 |
Partially correct |
515 ms |
684 KB |
Partially correct |
15 |
Partially correct |
408 ms |
684 KB |
Partially correct |
16 |
Partially correct |
329 ms |
684 KB |
Partially correct |
17 |
Partially correct |
421 ms |
684 KB |
Partially correct |
18 |
Partially correct |
305 ms |
804 KB |
Partially correct |
19 |
Partially correct |
321 ms |
796 KB |
Partially correct |
20 |
Partially correct |
348 ms |
684 KB |
Partially correct |
21 |
Partially correct |
28 ms |
768 KB |
Partially correct |
22 |
Partially correct |
37 ms |
684 KB |
Partially correct |
23 |
Partially correct |
61 ms |
688 KB |
Partially correct |
24 |
Partially correct |
2 ms |
768 KB |
Partially correct |
25 |
Partially correct |
2 ms |
768 KB |
Partially correct |
26 |
Partially correct |
3 ms |
768 KB |
Partially correct |
27 |
Partially correct |
3 ms |
768 KB |
Partially correct |
28 |
Partially correct |
1 ms |
768 KB |
Partially correct |
29 |
Partially correct |
317 ms |
804 KB |
Partially correct |
30 |
Partially correct |
321 ms |
684 KB |
Partially correct |
31 |
Partially correct |
316 ms |
800 KB |
Partially correct |
32 |
Partially correct |
274 ms |
804 KB |
Partially correct |
33 |
Partially correct |
321 ms |
684 KB |
Partially correct |
34 |
Partially correct |
180 ms |
684 KB |
Partially correct |
35 |
Partially correct |
253 ms |
916 KB |
Partially correct |
36 |
Partially correct |
307 ms |
908 KB |
Partially correct |
37 |
Partially correct |
312 ms |
800 KB |
Partially correct |
38 |
Partially correct |
301 ms |
816 KB |
Partially correct |
39 |
Partially correct |
321 ms |
800 KB |
Partially correct |
40 |
Partially correct |
357 ms |
808 KB |
Partially correct |
41 |
Partially correct |
399 ms |
940 KB |
Partially correct |
42 |
Partially correct |
44 ms |
892 KB |
Partially correct |
43 |
Partially correct |
83 ms |
684 KB |
Partially correct |
44 |
Partially correct |
88 ms |
1016 KB |
Partially correct |
45 |
Partially correct |
103 ms |
1024 KB |
Partially correct |
46 |
Partially correct |
219 ms |
684 KB |
Partially correct |
47 |
Partially correct |
204 ms |
684 KB |
Partially correct |
48 |
Partially correct |
50 ms |
824 KB |
Partially correct |
49 |
Partially correct |
45 ms |
876 KB |
Partially correct |