#include "dreaming.h"
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define oo 1000000000
vector<vector<pii>> ed;
vector<bool> visited;
vector<int> best;
vector<int> mx;
vector<int> cur;
void dfs(int v){
cur.pb(v);
visited[v] = true;
for (auto [x, t] : ed[v]){
if (!visited[x]) dfs(x);
}
}
int mxdist(int v, int pr){
int res = 0;
for (auto [x, t] : ed[v]){
if (x != pr){
res = max(res, mxdist(x, v) + t);
}
}
return res;
}
void findmn(int v){
cur.clear();
dfs(v);
int Min = oo, Max = 0;
for (auto x : cur){
int k = mxdist(x, -1);
Min = min(Min, k);
Max = max(Max, k);
}
best.pb(Min);
mx.pb(Max);
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
ed.resize(n);
visited.resize(n);
for (int i = 0; i < m; ++i) {
ed[a[i]].pb({b[i], t[i]});
ed[b[i]].pb({a[i], t[i]});
}
for (int i = 0; i < n; ++i) {
if (!visited[i]) findmn(i);
}
sort(best.rbegin(), best.rend());
sort(mx.rbegin(), mx.rend());
if (mx.size() == 1) return mx[0];
if (mx.size() == 2) return max(best[0] + best[1] + l, mx[0]);
return max(max(best[0]+best[1]+l, best[1]+best[2]+2*l), mx[0]);
}
Compilation message
dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:20:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
20 | for (auto [x, t] : ed[v]){
| ^
dreaming.cpp: In function 'int mxdist(int, int)':
dreaming.cpp:27:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
27 | for (auto [x, t] : ed[v]){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1060 ms |
9664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
288 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
268 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1060 ms |
9664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
5852 KB |
Output is correct |
2 |
Correct |
26 ms |
5928 KB |
Output is correct |
3 |
Correct |
37 ms |
5820 KB |
Output is correct |
4 |
Correct |
28 ms |
5952 KB |
Output is correct |
5 |
Correct |
33 ms |
5824 KB |
Output is correct |
6 |
Correct |
33 ms |
6444 KB |
Output is correct |
7 |
Correct |
25 ms |
6216 KB |
Output is correct |
8 |
Correct |
24 ms |
5776 KB |
Output is correct |
9 |
Correct |
23 ms |
5788 KB |
Output is correct |
10 |
Correct |
25 ms |
6048 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
8 ms |
3624 KB |
Output is correct |
13 |
Correct |
8 ms |
3700 KB |
Output is correct |
14 |
Correct |
8 ms |
3608 KB |
Output is correct |
15 |
Correct |
8 ms |
3616 KB |
Output is correct |
16 |
Correct |
8 ms |
3580 KB |
Output is correct |
17 |
Correct |
9 ms |
3532 KB |
Output is correct |
18 |
Correct |
10 ms |
3656 KB |
Output is correct |
19 |
Correct |
8 ms |
3576 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
8 ms |
3576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
284 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
288 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
268 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
464 KB |
Output is correct |
28 |
Correct |
3 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
460 KB |
Output is correct |
31 |
Correct |
5 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
464 KB |
Output is correct |
34 |
Correct |
4 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
288 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
288 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
1 ms |
204 KB |
Output is correct |
45 |
Correct |
1 ms |
204 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
1 ms |
208 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
1 ms |
208 KB |
Output is correct |
52 |
Correct |
1 ms |
204 KB |
Output is correct |
53 |
Correct |
1 ms |
204 KB |
Output is correct |
54 |
Correct |
173 ms |
632 KB |
Output is correct |
55 |
Correct |
173 ms |
668 KB |
Output is correct |
56 |
Correct |
3 ms |
460 KB |
Output is correct |
57 |
Correct |
1 ms |
460 KB |
Output is correct |
58 |
Correct |
71 ms |
556 KB |
Output is correct |
59 |
Correct |
110 ms |
460 KB |
Output is correct |
60 |
Correct |
2 ms |
460 KB |
Output is correct |
61 |
Correct |
2 ms |
460 KB |
Output is correct |
62 |
Correct |
54 ms |
552 KB |
Output is correct |
63 |
Correct |
99 ms |
560 KB |
Output is correct |
64 |
Correct |
1 ms |
332 KB |
Output is correct |
65 |
Correct |
3 ms |
460 KB |
Output is correct |
66 |
Correct |
127 ms |
460 KB |
Output is correct |
67 |
Correct |
60 ms |
460 KB |
Output is correct |
68 |
Correct |
2 ms |
460 KB |
Output is correct |
69 |
Correct |
2 ms |
460 KB |
Output is correct |
70 |
Correct |
1 ms |
460 KB |
Output is correct |
71 |
Correct |
2 ms |
460 KB |
Output is correct |
72 |
Correct |
94 ms |
564 KB |
Output is correct |
73 |
Correct |
100 ms |
556 KB |
Output is correct |
74 |
Correct |
3 ms |
556 KB |
Output is correct |
75 |
Correct |
4 ms |
464 KB |
Output is correct |
76 |
Correct |
70 ms |
552 KB |
Output is correct |
77 |
Correct |
97 ms |
588 KB |
Output is correct |
78 |
Correct |
2 ms |
424 KB |
Output is correct |
79 |
Correct |
2 ms |
428 KB |
Output is correct |
80 |
Correct |
3 ms |
332 KB |
Output is correct |
81 |
Correct |
1 ms |
332 KB |
Output is correct |
82 |
Correct |
3 ms |
460 KB |
Output is correct |
83 |
Correct |
3 ms |
432 KB |
Output is correct |
84 |
Correct |
10 ms |
440 KB |
Output is correct |
85 |
Correct |
1 ms |
416 KB |
Output is correct |
86 |
Correct |
36 ms |
464 KB |
Output is correct |
87 |
Correct |
92 ms |
560 KB |
Output is correct |
88 |
Correct |
2 ms |
460 KB |
Output is correct |
89 |
Correct |
2 ms |
460 KB |
Output is correct |
90 |
Correct |
2 ms |
460 KB |
Output is correct |
91 |
Correct |
1 ms |
460 KB |
Output is correct |
92 |
Correct |
33 ms |
460 KB |
Output is correct |
93 |
Correct |
30 ms |
408 KB |
Output is correct |
94 |
Correct |
33 ms |
496 KB |
Output is correct |
95 |
Correct |
48 ms |
504 KB |
Output is correct |
96 |
Correct |
40 ms |
460 KB |
Output is correct |
97 |
Correct |
40 ms |
524 KB |
Output is correct |
98 |
Correct |
48 ms |
532 KB |
Output is correct |
99 |
Correct |
94 ms |
560 KB |
Output is correct |
100 |
Correct |
60 ms |
520 KB |
Output is correct |
101 |
Correct |
57 ms |
460 KB |
Output is correct |
102 |
Correct |
1 ms |
204 KB |
Output is correct |
103 |
Correct |
1 ms |
204 KB |
Output is correct |
104 |
Correct |
1 ms |
204 KB |
Output is correct |
105 |
Correct |
1 ms |
204 KB |
Output is correct |
106 |
Correct |
1 ms |
204 KB |
Output is correct |
107 |
Correct |
1 ms |
204 KB |
Output is correct |
108 |
Correct |
1 ms |
204 KB |
Output is correct |
109 |
Correct |
1 ms |
204 KB |
Output is correct |
110 |
Correct |
1 ms |
204 KB |
Output is correct |
111 |
Correct |
1 ms |
204 KB |
Output is correct |
112 |
Correct |
2 ms |
204 KB |
Output is correct |
113 |
Correct |
7 ms |
332 KB |
Output is correct |
114 |
Correct |
11 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1060 ms |
9664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |