#include <bits/stdc++.h>
#include "stations.h"
#define DIMN 1010
using namespace std;
int poz;
int lab[DIMN] , last[DIMN] , niv[DIMN];
vector <int> ww[DIMN];
void dfs (int nod , int tt , int lvl){
int i , vecin;
//printf ("%d ", nod);
if (lvl % 2 == 0)
poz++;
lab[nod] = poz;
niv[nod] = lvl;
for (i = 0 ; i < ww[nod].size() ; i++){
vecin = ww[nod][i];
if (vecin != tt){
dfs (vecin , nod , lvl + 1);
}
}
if (lvl % 2 == 1)
poz++;
last[nod] = poz;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels;
labels.resize(n);
for (int i = 0 ; i < n ; i++)
ww[i].clear();
for (int i = 0; i <= n - 2; i++) {
ww[u[i]].push_back(v[i]);
ww[v[i]].push_back(u[i]);
}
poz = -1;
dfs (0 , -1 , 0);
for (int i = 0 ; i < n ; i++){
if (niv[i] % 2 == 0)
labels[i] = lab[i];
else labels[i] = last[i];
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
int i;
if (c.size() == 1)
return c[0];
if (s == 0){ /// incep din 0, e nivel par oricum
for (i = 0 ; i <= c.size() - 1 ; i++){
if (c[i] < t && t <= c[i + 1])
return c[i + 1];
}
return c[0];
}
else { /// unul dintre vecini e clar tatal
if (s < c[0]){ /// s e un nivel par
if (s <= t && t <= c[0])
return c[0];
for (i = 0 ; i <= c.size() - 2 ; i++){
if (c[i] < t && t <= c[i + 1])
return c[i + 1];
}
return c.back();
}
else { /// s e un nivel impar
for (i = 1 ; i < c.size() - 1 ; i++){
if (c[i] <= t && t < c[i + 1]){
return c[i];
}
}
if (t >= c.back() && t < s)
return c.back();
return c[0];
}
}
}
Compilation message
stations.cpp: In function 'void dfs(int, int, int)':
stations.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (i = 0 ; i < ww[nod].size() ; i++){
| ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:69:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (i = 0 ; i <= c.size() - 1 ; i++){
| ~~^~~~~~~~~~~~~~~
stations.cpp:84:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (i = 0 ; i <= c.size() - 2 ; i++){
| ~~^~~~~~~~~~~~~~~
stations.cpp:95:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for (i = 1 ; i < c.size() - 1 ; i++){
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
548 ms |
1280 KB |
Output is correct |
2 |
Correct |
480 ms |
1024 KB |
Output is correct |
3 |
Correct |
864 ms |
864 KB |
Output is correct |
4 |
Correct |
651 ms |
776 KB |
Output is correct |
5 |
Correct |
558 ms |
768 KB |
Output is correct |
6 |
Correct |
480 ms |
1024 KB |
Output is correct |
7 |
Correct |
550 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
780 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
451 ms |
796 KB |
Output is correct |
2 |
Correct |
528 ms |
812 KB |
Output is correct |
3 |
Correct |
1041 ms |
864 KB |
Output is correct |
4 |
Correct |
671 ms |
864 KB |
Output is correct |
5 |
Correct |
658 ms |
868 KB |
Output is correct |
6 |
Correct |
468 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
635 ms |
1024 KB |
Output is correct |
2 |
Correct |
469 ms |
1008 KB |
Output is correct |
3 |
Correct |
923 ms |
864 KB |
Output is correct |
4 |
Correct |
669 ms |
864 KB |
Output is correct |
5 |
Correct |
616 ms |
856 KB |
Output is correct |
6 |
Correct |
463 ms |
1024 KB |
Output is correct |
7 |
Correct |
511 ms |
1024 KB |
Output is correct |
8 |
Correct |
3 ms |
996 KB |
Output is correct |
9 |
Correct |
4 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
674 ms |
1024 KB |
Output is correct |
12 |
Correct |
478 ms |
1008 KB |
Output is correct |
13 |
Correct |
482 ms |
1008 KB |
Output is correct |
14 |
Correct |
543 ms |
768 KB |
Output is correct |
15 |
Correct |
73 ms |
856 KB |
Output is correct |
16 |
Correct |
70 ms |
768 KB |
Output is correct |
17 |
Correct |
111 ms |
928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
946 ms |
768 KB |
Output is correct |
2 |
Correct |
723 ms |
864 KB |
Output is correct |
3 |
Correct |
549 ms |
868 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
4 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
856 KB |
Output is correct |
7 |
Correct |
623 ms |
860 KB |
Output is correct |
8 |
Correct |
941 ms |
1008 KB |
Output is correct |
9 |
Correct |
684 ms |
864 KB |
Output is correct |
10 |
Correct |
633 ms |
864 KB |
Output is correct |
11 |
Correct |
7 ms |
768 KB |
Output is correct |
12 |
Correct |
5 ms |
868 KB |
Output is correct |
13 |
Correct |
5 ms |
864 KB |
Output is correct |
14 |
Correct |
5 ms |
864 KB |
Output is correct |
15 |
Correct |
1 ms |
768 KB |
Output is correct |
16 |
Correct |
519 ms |
868 KB |
Output is correct |
17 |
Correct |
581 ms |
768 KB |
Output is correct |
18 |
Correct |
575 ms |
768 KB |
Output is correct |
19 |
Correct |
481 ms |
864 KB |
Output is correct |
20 |
Correct |
493 ms |
864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
545 ms |
1024 KB |
Output is correct |
2 |
Correct |
463 ms |
1264 KB |
Output is correct |
3 |
Correct |
864 ms |
1024 KB |
Output is correct |
4 |
Correct |
656 ms |
860 KB |
Output is correct |
5 |
Correct |
585 ms |
1040 KB |
Output is correct |
6 |
Correct |
453 ms |
1024 KB |
Output is correct |
7 |
Correct |
442 ms |
780 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
868 KB |
Output is correct |
11 |
Correct |
451 ms |
768 KB |
Output is correct |
12 |
Correct |
541 ms |
820 KB |
Output is correct |
13 |
Correct |
850 ms |
1008 KB |
Output is correct |
14 |
Correct |
649 ms |
872 KB |
Output is correct |
15 |
Correct |
581 ms |
1024 KB |
Output is correct |
16 |
Correct |
462 ms |
816 KB |
Output is correct |
17 |
Correct |
570 ms |
768 KB |
Output is correct |
18 |
Correct |
469 ms |
1024 KB |
Output is correct |
19 |
Correct |
498 ms |
1116 KB |
Output is correct |
20 |
Correct |
451 ms |
768 KB |
Output is correct |
21 |
Correct |
68 ms |
856 KB |
Output is correct |
22 |
Correct |
76 ms |
768 KB |
Output is correct |
23 |
Correct |
124 ms |
1024 KB |
Output is correct |
24 |
Correct |
5 ms |
856 KB |
Output is correct |
25 |
Correct |
6 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
868 KB |
Output is correct |
27 |
Correct |
3 ms |
876 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
29 |
Correct |
560 ms |
768 KB |
Output is correct |
30 |
Correct |
484 ms |
860 KB |
Output is correct |
31 |
Correct |
492 ms |
864 KB |
Output is correct |
32 |
Correct |
497 ms |
768 KB |
Output is correct |
33 |
Correct |
532 ms |
1040 KB |
Output is correct |
34 |
Correct |
336 ms |
1024 KB |
Output is correct |
35 |
Correct |
457 ms |
1024 KB |
Output is correct |
36 |
Correct |
448 ms |
1108 KB |
Output is correct |
37 |
Correct |
487 ms |
892 KB |
Output is correct |
38 |
Correct |
430 ms |
888 KB |
Output is correct |
39 |
Correct |
450 ms |
1024 KB |
Output is correct |
40 |
Correct |
463 ms |
1032 KB |
Output is correct |
41 |
Correct |
460 ms |
1004 KB |
Output is correct |
42 |
Correct |
60 ms |
816 KB |
Output is correct |
43 |
Correct |
101 ms |
812 KB |
Output is correct |
44 |
Correct |
131 ms |
784 KB |
Output is correct |
45 |
Correct |
177 ms |
776 KB |
Output is correct |
46 |
Correct |
300 ms |
808 KB |
Output is correct |
47 |
Correct |
309 ms |
768 KB |
Output is correct |
48 |
Correct |
59 ms |
1024 KB |
Output is correct |
49 |
Correct |
64 ms |
1024 KB |
Output is correct |