#include <bits/stdc++.h>
#include "stations.h"
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 1001;
const ll VMAX = 1000001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 1000000;
const ll nr_of_bits = 16;
vector <int> sol;
int lvl[NMAX];
vector <int> g[NMAX];
int stamp;
void DFS(int node, int p){
lvl[node] = lvl[p] + 1;
if(lvl[node] % 2){
sol[node] = stamp++;
}
for(auto x : g[node]){
if(x == p)
continue;
DFS(x, node);
}
if(lvl[node] % 2 == 0)
sol[node] = stamp++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
sol.clear();
sol.resize(n);
stamp = 0;
for(int i = 0; i < n; i++){
g[i].clear();
lvl[i] = 0;
}
for (int i = 0; i < n - 1; i++) {
int a = u[i];
int b = v[i];
g[a].push_back(b);
g[b].push_back(a);
}
DFS(0, -1);
return sol;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(), c.end());
if(s >= c[0])
reverse(c.begin(), c.end());
for(int i = 0; i < c.size() - 1; i++){
if(c[i] > s && s <= t && t <= c[i]){
return c[i];
}else if(c[i] < s && c[i] <= t && t <= s){
return c[i];
}
}
return c.back();
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i = 0; i < c.size() - 1; i++){
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
449 ms |
548 KB |
Output is correct |
2 |
Correct |
392 ms |
656 KB |
Output is correct |
3 |
Correct |
738 ms |
528 KB |
Output is correct |
4 |
Correct |
530 ms |
532 KB |
Output is correct |
5 |
Correct |
493 ms |
532 KB |
Output is correct |
6 |
Correct |
411 ms |
544 KB |
Output is correct |
7 |
Correct |
400 ms |
544 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
5 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
392 ms |
604 KB |
Output is correct |
2 |
Correct |
430 ms |
536 KB |
Output is correct |
3 |
Correct |
747 ms |
416 KB |
Output is correct |
4 |
Correct |
551 ms |
416 KB |
Output is correct |
5 |
Correct |
486 ms |
420 KB |
Output is correct |
6 |
Correct |
373 ms |
536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
441 ms |
548 KB |
Output is correct |
2 |
Correct |
415 ms |
640 KB |
Output is correct |
3 |
Correct |
707 ms |
420 KB |
Output is correct |
4 |
Correct |
583 ms |
420 KB |
Output is correct |
5 |
Correct |
459 ms |
536 KB |
Output is correct |
6 |
Correct |
364 ms |
540 KB |
Output is correct |
7 |
Correct |
363 ms |
544 KB |
Output is correct |
8 |
Correct |
1 ms |
500 KB |
Output is correct |
9 |
Correct |
4 ms |
500 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
488 ms |
532 KB |
Output is correct |
12 |
Correct |
358 ms |
648 KB |
Output is correct |
13 |
Correct |
427 ms |
636 KB |
Output is correct |
14 |
Correct |
347 ms |
528 KB |
Output is correct |
15 |
Correct |
45 ms |
612 KB |
Output is correct |
16 |
Correct |
65 ms |
532 KB |
Output is correct |
17 |
Correct |
88 ms |
572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
713 ms |
516 KB |
Output is correct |
2 |
Correct |
583 ms |
420 KB |
Output is correct |
3 |
Correct |
408 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
4 ms |
572 KB |
Output is correct |
6 |
Correct |
0 ms |
492 KB |
Output is correct |
7 |
Correct |
475 ms |
416 KB |
Output is correct |
8 |
Correct |
677 ms |
416 KB |
Output is correct |
9 |
Correct |
567 ms |
532 KB |
Output is correct |
10 |
Correct |
453 ms |
548 KB |
Output is correct |
11 |
Correct |
3 ms |
500 KB |
Output is correct |
12 |
Correct |
4 ms |
444 KB |
Output is correct |
13 |
Correct |
3 ms |
492 KB |
Output is correct |
14 |
Correct |
3 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
418 ms |
416 KB |
Output is correct |
17 |
Correct |
416 ms |
528 KB |
Output is correct |
18 |
Correct |
443 ms |
416 KB |
Output is correct |
19 |
Correct |
411 ms |
536 KB |
Output is correct |
20 |
Correct |
416 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
453 ms |
548 KB |
Output is correct |
2 |
Correct |
417 ms |
540 KB |
Output is correct |
3 |
Correct |
692 ms |
416 KB |
Output is correct |
4 |
Correct |
560 ms |
532 KB |
Output is correct |
5 |
Correct |
542 ms |
676 KB |
Output is correct |
6 |
Correct |
323 ms |
520 KB |
Output is correct |
7 |
Correct |
368 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
4 ms |
496 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
398 ms |
544 KB |
Output is correct |
12 |
Correct |
433 ms |
524 KB |
Output is correct |
13 |
Correct |
751 ms |
532 KB |
Output is correct |
14 |
Correct |
545 ms |
416 KB |
Output is correct |
15 |
Correct |
462 ms |
564 KB |
Output is correct |
16 |
Correct |
402 ms |
532 KB |
Output is correct |
17 |
Correct |
463 ms |
420 KB |
Output is correct |
18 |
Correct |
357 ms |
548 KB |
Output is correct |
19 |
Correct |
375 ms |
548 KB |
Output is correct |
20 |
Correct |
374 ms |
536 KB |
Output is correct |
21 |
Correct |
52 ms |
572 KB |
Output is correct |
22 |
Correct |
57 ms |
600 KB |
Output is correct |
23 |
Correct |
101 ms |
612 KB |
Output is correct |
24 |
Correct |
6 ms |
492 KB |
Output is correct |
25 |
Correct |
5 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
500 KB |
Output is correct |
27 |
Correct |
4 ms |
500 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
410 ms |
536 KB |
Output is correct |
30 |
Correct |
382 ms |
420 KB |
Output is correct |
31 |
Correct |
400 ms |
420 KB |
Output is correct |
32 |
Correct |
469 ms |
420 KB |
Output is correct |
33 |
Correct |
430 ms |
420 KB |
Output is correct |
34 |
Correct |
276 ms |
532 KB |
Output is correct |
35 |
Correct |
337 ms |
652 KB |
Output is correct |
36 |
Correct |
381 ms |
652 KB |
Output is correct |
37 |
Correct |
376 ms |
636 KB |
Output is correct |
38 |
Correct |
404 ms |
652 KB |
Output is correct |
39 |
Correct |
373 ms |
640 KB |
Output is correct |
40 |
Correct |
343 ms |
660 KB |
Output is correct |
41 |
Correct |
372 ms |
668 KB |
Output is correct |
42 |
Correct |
55 ms |
600 KB |
Output is correct |
43 |
Correct |
98 ms |
676 KB |
Output is correct |
44 |
Correct |
115 ms |
544 KB |
Output is correct |
45 |
Correct |
135 ms |
532 KB |
Output is correct |
46 |
Correct |
254 ms |
536 KB |
Output is correct |
47 |
Correct |
257 ms |
548 KB |
Output is correct |
48 |
Correct |
48 ms |
704 KB |
Output is correct |
49 |
Correct |
56 ms |
720 KB |
Output is correct |