#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
//#define int long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
vvi adj;
vi labels;
int counter = 0;
void dfs(int node, int parent, bool isFirst)
{
if (isFirst)
labels[node] = counter++;
for (int child : adj[node])
{
if (child == parent)
continue;
dfs(child, node, !isFirst);
}
if (!isFirst)
labels[node] = counter++;
}
vi label(int n, int k, vi u, vi v)
{
counter = 0;
labels.assign(n, 0);
adj.assign(n, {});
loop(i, n - 1)
{
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, -1, true);
return labels;
}
int find_next_station(int s, int t, vi c)
{
sort(all(c));
if (c.back() < s)
{
if (t > s || t <= c[0])
return c[0];
for (int i = c.size() - 1; i >= 0; i--)
{
if (t >= c[i])
return c[i];
}
}
else
{
if (t < s || t >= c.back())
return c.back();
for (int i = 0; i < c.size(); i++)
{
if (t <= c[i])
return c[i];
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, vi)':
stations.cpp:88:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for (int i = 0; i < c.size(); i++)
| ~~^~~~~~~~~~
stations.cpp:94:1: warning: control reaches end of non-void function [-Wreturn-type]
94 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
352 ms |
940 KB |
Output is correct |
2 |
Correct |
290 ms |
940 KB |
Output is correct |
3 |
Correct |
632 ms |
684 KB |
Output is correct |
4 |
Correct |
463 ms |
684 KB |
Output is correct |
5 |
Correct |
411 ms |
684 KB |
Output is correct |
6 |
Correct |
302 ms |
684 KB |
Output is correct |
7 |
Correct |
310 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
303 ms |
684 KB |
Output is correct |
2 |
Correct |
357 ms |
684 KB |
Output is correct |
3 |
Correct |
571 ms |
684 KB |
Output is correct |
4 |
Correct |
464 ms |
684 KB |
Output is correct |
5 |
Correct |
400 ms |
684 KB |
Output is correct |
6 |
Correct |
288 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
940 KB |
Output is correct |
2 |
Correct |
291 ms |
940 KB |
Output is correct |
3 |
Correct |
605 ms |
684 KB |
Output is correct |
4 |
Correct |
446 ms |
684 KB |
Output is correct |
5 |
Correct |
407 ms |
684 KB |
Output is correct |
6 |
Correct |
306 ms |
684 KB |
Output is correct |
7 |
Correct |
298 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
764 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
11 |
Correct |
428 ms |
680 KB |
Output is correct |
12 |
Correct |
293 ms |
932 KB |
Output is correct |
13 |
Correct |
326 ms |
1016 KB |
Output is correct |
14 |
Correct |
270 ms |
684 KB |
Output is correct |
15 |
Correct |
27 ms |
788 KB |
Output is correct |
16 |
Correct |
38 ms |
768 KB |
Output is correct |
17 |
Correct |
63 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
607 ms |
684 KB |
Output is correct |
2 |
Correct |
456 ms |
684 KB |
Output is correct |
3 |
Correct |
390 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
764 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
0 ms |
768 KB |
Output is correct |
7 |
Correct |
414 ms |
684 KB |
Output is correct |
8 |
Correct |
617 ms |
684 KB |
Output is correct |
9 |
Correct |
482 ms |
684 KB |
Output is correct |
10 |
Correct |
445 ms |
684 KB |
Output is correct |
11 |
Correct |
3 ms |
768 KB |
Output is correct |
12 |
Correct |
3 ms |
768 KB |
Output is correct |
13 |
Correct |
2 ms |
768 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
0 ms |
760 KB |
Output is correct |
16 |
Correct |
384 ms |
936 KB |
Output is correct |
17 |
Correct |
386 ms |
684 KB |
Output is correct |
18 |
Correct |
335 ms |
684 KB |
Output is correct |
19 |
Correct |
349 ms |
684 KB |
Output is correct |
20 |
Correct |
344 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
940 KB |
Output is correct |
2 |
Correct |
309 ms |
940 KB |
Output is correct |
3 |
Correct |
569 ms |
684 KB |
Output is correct |
4 |
Correct |
419 ms |
684 KB |
Output is correct |
5 |
Correct |
398 ms |
684 KB |
Output is correct |
6 |
Correct |
346 ms |
936 KB |
Output is correct |
7 |
Correct |
302 ms |
712 KB |
Output is correct |
8 |
Correct |
2 ms |
776 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
308 ms |
684 KB |
Output is correct |
12 |
Correct |
326 ms |
684 KB |
Output is correct |
13 |
Correct |
600 ms |
684 KB |
Output is correct |
14 |
Correct |
454 ms |
684 KB |
Output is correct |
15 |
Correct |
418 ms |
684 KB |
Output is correct |
16 |
Correct |
333 ms |
684 KB |
Output is correct |
17 |
Correct |
410 ms |
684 KB |
Output is correct |
18 |
Correct |
287 ms |
684 KB |
Output is correct |
19 |
Correct |
340 ms |
1020 KB |
Output is correct |
20 |
Correct |
293 ms |
688 KB |
Output is correct |
21 |
Correct |
41 ms |
764 KB |
Output is correct |
22 |
Correct |
38 ms |
768 KB |
Output is correct |
23 |
Correct |
55 ms |
716 KB |
Output is correct |
24 |
Correct |
2 ms |
776 KB |
Output is correct |
25 |
Correct |
3 ms |
776 KB |
Output is correct |
26 |
Correct |
2 ms |
768 KB |
Output is correct |
27 |
Correct |
2 ms |
776 KB |
Output is correct |
28 |
Correct |
0 ms |
768 KB |
Output is correct |
29 |
Correct |
352 ms |
684 KB |
Output is correct |
30 |
Correct |
340 ms |
684 KB |
Output is correct |
31 |
Correct |
318 ms |
684 KB |
Output is correct |
32 |
Correct |
325 ms |
688 KB |
Output is correct |
33 |
Correct |
326 ms |
684 KB |
Output is correct |
34 |
Correct |
202 ms |
940 KB |
Output is correct |
35 |
Correct |
305 ms |
940 KB |
Output is correct |
36 |
Correct |
306 ms |
1284 KB |
Output is correct |
37 |
Correct |
326 ms |
784 KB |
Output is correct |
38 |
Correct |
343 ms |
764 KB |
Output is correct |
39 |
Correct |
300 ms |
780 KB |
Output is correct |
40 |
Correct |
282 ms |
932 KB |
Output is correct |
41 |
Correct |
321 ms |
932 KB |
Output is correct |
42 |
Correct |
30 ms |
736 KB |
Output is correct |
43 |
Correct |
82 ms |
684 KB |
Output is correct |
44 |
Correct |
70 ms |
748 KB |
Output is correct |
45 |
Correct |
123 ms |
684 KB |
Output is correct |
46 |
Correct |
212 ms |
684 KB |
Output is correct |
47 |
Correct |
183 ms |
684 KB |
Output is correct |
48 |
Correct |
39 ms |
1020 KB |
Output is correct |
49 |
Correct |
30 ms |
796 KB |
Output is correct |