#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1005], ans;
int dfs(int U, int P, int cnt, bool X)
{
if (X)
{
ans[U]=cnt;
cnt++;
for (int i=0; i<adj[U].size(); i++)
{
int V=adj[U][i];
if (V!=P)
cnt=dfs(V, U, cnt, 0);
}
}
else
{
for (int i=0; i<adj[U].size(); i++)
{
int V=adj[U][i];
if (V!=P)
cnt=dfs(V, U, cnt, 1);
}
ans[U]=cnt;
cnt++;
}
return cnt;
}
vector<int> label(int N, int K, vector<int> U, vector<int> V)
{
for (int i=0; i<N; i++)
adj[i].clear();
for (int i=0; i<N-1; i++)
{
adj[U[i]].push_back(V[i]);
adj[V[i]].push_back(U[i]);
}
ans.clear();
for (int i=0; i<N; i++)
ans.push_back(0);
dfs(0, -1, 0, 1);
return ans;
}
int find_next_station(int S, int T, vector<int> C)
{
if (S<C[0])
{
int P=C[C.size()-1];
if (T<S || T>=P)
return P;
for (int i=0; i<C.size(); i++)
if (T<=C[i])
return C[i];
}
else
{
int P=C[0];
if (T<=P || T>S)
return P;
for (int i=C.size()-1; i>=0; i--)
if (T>=C[i])
return C[i];
}
}
Compilation message
stations.cpp: In function 'int dfs(int, int, int, bool)':
stations.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for (int i=0; i<adj[U].size(); i++)
| ~^~~~~~~~~~~~~~
stations.cpp:20:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i=0; i<adj[U].size(); i++)
| ~^~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i=0; i<C.size(); i++)
| ~^~~~~~~~~
stations.cpp:66:1: warning: control reaches end of non-void function [-Wreturn-type]
66 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
472 ms |
528 KB |
Output is correct |
2 |
Correct |
401 ms |
616 KB |
Output is correct |
3 |
Correct |
998 ms |
404 KB |
Output is correct |
4 |
Correct |
757 ms |
404 KB |
Output is correct |
5 |
Correct |
546 ms |
400 KB |
Output is correct |
6 |
Correct |
446 ms |
524 KB |
Output is correct |
7 |
Correct |
480 ms |
524 KB |
Output is correct |
8 |
Correct |
2 ms |
524 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
444 ms |
508 KB |
Output is correct |
2 |
Correct |
525 ms |
508 KB |
Output is correct |
3 |
Correct |
903 ms |
496 KB |
Output is correct |
4 |
Correct |
621 ms |
496 KB |
Output is correct |
5 |
Correct |
603 ms |
572 KB |
Output is correct |
6 |
Correct |
467 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
442 ms |
540 KB |
Output is correct |
2 |
Correct |
444 ms |
508 KB |
Output is correct |
3 |
Correct |
833 ms |
404 KB |
Output is correct |
4 |
Correct |
520 ms |
496 KB |
Output is correct |
5 |
Correct |
605 ms |
492 KB |
Output is correct |
6 |
Correct |
510 ms |
616 KB |
Output is correct |
7 |
Correct |
478 ms |
656 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
476 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
637 ms |
528 KB |
Output is correct |
12 |
Correct |
469 ms |
740 KB |
Output is correct |
13 |
Correct |
440 ms |
608 KB |
Output is correct |
14 |
Correct |
444 ms |
504 KB |
Output is correct |
15 |
Correct |
42 ms |
404 KB |
Output is correct |
16 |
Correct |
59 ms |
528 KB |
Output is correct |
17 |
Correct |
111 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
904 ms |
404 KB |
Output is correct |
2 |
Correct |
600 ms |
400 KB |
Output is correct |
3 |
Correct |
578 ms |
400 KB |
Output is correct |
4 |
Correct |
3 ms |
556 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
576 ms |
488 KB |
Output is correct |
8 |
Correct |
781 ms |
400 KB |
Output is correct |
9 |
Correct |
614 ms |
492 KB |
Output is correct |
10 |
Correct |
555 ms |
488 KB |
Output is correct |
11 |
Correct |
6 ms |
472 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
476 KB |
Output is correct |
15 |
Correct |
3 ms |
476 KB |
Output is correct |
16 |
Correct |
512 ms |
492 KB |
Output is correct |
17 |
Correct |
513 ms |
496 KB |
Output is correct |
18 |
Correct |
506 ms |
404 KB |
Output is correct |
19 |
Correct |
486 ms |
404 KB |
Output is correct |
20 |
Correct |
572 ms |
540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
516 ms |
528 KB |
Output is correct |
2 |
Correct |
386 ms |
492 KB |
Output is correct |
3 |
Correct |
801 ms |
400 KB |
Output is correct |
4 |
Correct |
497 ms |
496 KB |
Output is correct |
5 |
Correct |
549 ms |
400 KB |
Output is correct |
6 |
Correct |
474 ms |
504 KB |
Output is correct |
7 |
Correct |
404 ms |
496 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
488 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
449 ms |
504 KB |
Output is correct |
12 |
Correct |
494 ms |
564 KB |
Output is correct |
13 |
Correct |
902 ms |
404 KB |
Output is correct |
14 |
Correct |
521 ms |
520 KB |
Output is correct |
15 |
Correct |
554 ms |
408 KB |
Output is correct |
16 |
Correct |
374 ms |
516 KB |
Output is correct |
17 |
Correct |
575 ms |
404 KB |
Output is correct |
18 |
Correct |
390 ms |
636 KB |
Output is correct |
19 |
Correct |
435 ms |
632 KB |
Output is correct |
20 |
Correct |
439 ms |
548 KB |
Output is correct |
21 |
Correct |
48 ms |
548 KB |
Output is correct |
22 |
Correct |
64 ms |
596 KB |
Output is correct |
23 |
Correct |
92 ms |
600 KB |
Output is correct |
24 |
Correct |
6 ms |
476 KB |
Output is correct |
25 |
Correct |
4 ms |
476 KB |
Output is correct |
26 |
Correct |
5 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
464 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
527 ms |
400 KB |
Output is correct |
30 |
Correct |
521 ms |
508 KB |
Output is correct |
31 |
Correct |
409 ms |
400 KB |
Output is correct |
32 |
Correct |
334 ms |
492 KB |
Output is correct |
33 |
Correct |
458 ms |
404 KB |
Output is correct |
34 |
Correct |
316 ms |
616 KB |
Output is correct |
35 |
Correct |
419 ms |
728 KB |
Output is correct |
36 |
Correct |
380 ms |
620 KB |
Output is correct |
37 |
Correct |
415 ms |
508 KB |
Output is correct |
38 |
Correct |
457 ms |
620 KB |
Output is correct |
39 |
Correct |
394 ms |
736 KB |
Output is correct |
40 |
Correct |
398 ms |
624 KB |
Output is correct |
41 |
Correct |
427 ms |
764 KB |
Output is correct |
42 |
Correct |
59 ms |
624 KB |
Output is correct |
43 |
Correct |
113 ms |
576 KB |
Output is correct |
44 |
Correct |
109 ms |
528 KB |
Output is correct |
45 |
Correct |
157 ms |
512 KB |
Output is correct |
46 |
Correct |
263 ms |
548 KB |
Output is correct |
47 |
Correct |
290 ms |
596 KB |
Output is correct |
48 |
Correct |
64 ms |
748 KB |
Output is correct |
49 |
Correct |
53 ms |
732 KB |
Output is correct |