#include <bits/stdc++.h>
using namespace std;
#include "dreaming.h"
#define pii array<int,2>
#define ll long long
vector<vector<pii>> g;
vector<bool> vis;
vector<int> dis1, dis2, dis3;
pii dfs(int node, int p, vector<int> &dis) {
vis[node]=true;
pii ret = {dis[node], node};
for (auto [ne, we] : g[node]) {
if (ne == p) continue;
dis[ne] = dis[node] + we;
ret = max(ret, dfs(ne, node, dis));
}
return ret;
}
int get_diam(int node, int p, vector<int> &d1, vector<int> &d2) {
int ret = max(d1[node], d2[node]);
for (auto [ne, we] : g[node]) {
if (ne == p) continue;
ret = min(ret, get_diam(ne, node, d1, d2));
}
return ret;
}
pii diameter(int node) {
dis1[node]=0;
auto [d1, n1] = dfs(node, -1, dis1);
auto [d2, n2] = dfs(n1, -1, dis2);
auto [d3, n3] = dfs(n2, -1, dis3);
return {get_diam(node, -1, dis2, dis3), d3};
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
g.resize(N);
dis1.assign(N, 0);
dis2.assign(N, 0);
dis3.assign(N, 0);
for (int i=0;i<M;i++) {
g[A[i]].push_back({B[i], T[i]});
g[B[i]].push_back({A[i], T[i]});
}
vis.assign(N, false);
vector<pii> dia;
for (int i=0;i<N;i++) {
if (vis[i]) continue;
dia.push_back(diameter(i));
}
sort(dia.begin(), dia.end(), greater<pii>());
// for (int &x:dia) {
// cout << x << " ";
// }
// cout<<"\n";
return max(dia[0][0] + dia[1][0] + L, max(dia[0][1], dia[1][1]));
}
Compilation message
dreaming.cpp: In function 'std::array<int, 2> dfs(int, int, std::vector<int>&)':
dreaming.cpp:16:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
16 | for (auto [ne, we] : g[node]) {
| ^
dreaming.cpp: In function 'int get_diam(int, int, std::vector<int>&, std::vector<int>&)':
dreaming.cpp:26:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
26 | for (auto [ne, we] : g[node]) {
| ^
dreaming.cpp: In function 'std::array<int, 2> diameter(int)':
dreaming.cpp:36:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
36 | auto [d1, n1] = dfs(node, -1, dis1);
| ^
dreaming.cpp:37:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
37 | auto [d2, n2] = dfs(n1, -1, dis2);
| ^
dreaming.cpp:38:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
38 | auto [d3, n3] = dfs(n2, -1, dis3);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
15944 KB |
Output is correct |
2 |
Correct |
35 ms |
15696 KB |
Output is correct |
3 |
Correct |
24 ms |
10720 KB |
Output is correct |
4 |
Correct |
6 ms |
2652 KB |
Output is correct |
5 |
Correct |
5 ms |
1624 KB |
Output is correct |
6 |
Correct |
10 ms |
3668 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
20 ms |
5796 KB |
Output is correct |
9 |
Correct |
26 ms |
8024 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
36 ms |
10772 KB |
Output is correct |
12 |
Correct |
39 ms |
13128 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
15944 KB |
Output is correct |
2 |
Correct |
35 ms |
15696 KB |
Output is correct |
3 |
Correct |
24 ms |
10720 KB |
Output is correct |
4 |
Correct |
6 ms |
2652 KB |
Output is correct |
5 |
Correct |
5 ms |
1624 KB |
Output is correct |
6 |
Correct |
10 ms |
3668 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
20 ms |
5796 KB |
Output is correct |
9 |
Correct |
26 ms |
8024 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
36 ms |
10772 KB |
Output is correct |
12 |
Correct |
39 ms |
13128 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
444 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
43 ms |
15788 KB |
Output is correct |
40 |
Correct |
35 ms |
15820 KB |
Output is correct |
41 |
Correct |
24 ms |
10580 KB |
Output is correct |
42 |
Correct |
6 ms |
2648 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
1 ms |
344 KB |
Output is correct |
45 |
Correct |
0 ms |
344 KB |
Output is correct |
46 |
Correct |
0 ms |
444 KB |
Output is correct |
47 |
Correct |
0 ms |
344 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
56 ms |
10472 KB |
Output is correct |
58 |
Correct |
49 ms |
10320 KB |
Output is correct |
59 |
Correct |
43 ms |
10320 KB |
Output is correct |
60 |
Correct |
46 ms |
10324 KB |
Output is correct |
61 |
Correct |
43 ms |
10332 KB |
Output is correct |
62 |
Correct |
45 ms |
10324 KB |
Output is correct |
63 |
Correct |
43 ms |
10064 KB |
Output is correct |
64 |
Correct |
38 ms |
10064 KB |
Output is correct |
65 |
Correct |
46 ms |
10440 KB |
Output is correct |
66 |
Correct |
43 ms |
10292 KB |
Output is correct |
67 |
Correct |
44 ms |
10332 KB |
Output is correct |
68 |
Correct |
44 ms |
10376 KB |
Output is correct |
69 |
Correct |
54 ms |
10580 KB |
Output is correct |
70 |
Correct |
45 ms |
10584 KB |
Output is correct |
71 |
Correct |
0 ms |
344 KB |
Output is correct |
72 |
Correct |
1 ms |
604 KB |
Output is correct |
73 |
Correct |
1 ms |
604 KB |
Output is correct |
74 |
Correct |
1 ms |
604 KB |
Output is correct |
75 |
Correct |
1 ms |
500 KB |
Output is correct |
76 |
Correct |
1 ms |
604 KB |
Output is correct |
77 |
Correct |
1 ms |
604 KB |
Output is correct |
78 |
Correct |
1 ms |
604 KB |
Output is correct |
79 |
Correct |
2 ms |
600 KB |
Output is correct |
80 |
Correct |
50 ms |
10288 KB |
Output is correct |
81 |
Correct |
48 ms |
10324 KB |
Output is correct |
82 |
Correct |
46 ms |
10332 KB |
Output is correct |
83 |
Correct |
43 ms |
10320 KB |
Output is correct |
84 |
Correct |
1 ms |
600 KB |
Output is correct |
85 |
Correct |
1 ms |
604 KB |
Output is correct |
86 |
Correct |
1 ms |
604 KB |
Output is correct |
87 |
Correct |
1 ms |
604 KB |
Output is correct |
88 |
Correct |
1 ms |
604 KB |
Output is correct |
89 |
Correct |
1 ms |
604 KB |
Output is correct |
90 |
Correct |
1 ms |
604 KB |
Output is correct |
91 |
Correct |
2 ms |
600 KB |
Output is correct |
92 |
Correct |
2 ms |
604 KB |
Output is correct |
93 |
Correct |
1 ms |
720 KB |
Output is correct |
94 |
Correct |
1 ms |
348 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
1 ms |
348 KB |
Output is correct |
97 |
Correct |
0 ms |
348 KB |
Output is correct |
98 |
Correct |
0 ms |
348 KB |
Output is correct |
99 |
Correct |
0 ms |
348 KB |
Output is correct |
100 |
Correct |
0 ms |
444 KB |
Output is correct |
101 |
Correct |
0 ms |
348 KB |
Output is correct |
102 |
Correct |
0 ms |
348 KB |
Output is correct |
103 |
Correct |
0 ms |
348 KB |
Output is correct |
104 |
Correct |
4 ms |
1628 KB |
Output is correct |
105 |
Correct |
12 ms |
3676 KB |
Output is correct |
106 |
Correct |
1 ms |
348 KB |
Output is correct |
107 |
Correct |
20 ms |
5760 KB |
Output is correct |
108 |
Correct |
28 ms |
7964 KB |
Output is correct |
109 |
Correct |
1 ms |
348 KB |
Output is correct |
110 |
Correct |
36 ms |
10792 KB |
Output is correct |
111 |
Correct |
41 ms |
13144 KB |
Output is correct |
112 |
Correct |
1 ms |
348 KB |
Output is correct |
113 |
Correct |
53 ms |
17492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
7136 KB |
Output is correct |
2 |
Incorrect |
16 ms |
7128 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
15944 KB |
Output is correct |
2 |
Correct |
35 ms |
15696 KB |
Output is correct |
3 |
Correct |
24 ms |
10720 KB |
Output is correct |
4 |
Correct |
6 ms |
2652 KB |
Output is correct |
5 |
Correct |
5 ms |
1624 KB |
Output is correct |
6 |
Correct |
10 ms |
3668 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
20 ms |
5796 KB |
Output is correct |
9 |
Correct |
26 ms |
8024 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
36 ms |
10772 KB |
Output is correct |
12 |
Correct |
39 ms |
13128 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
444 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
43 ms |
15788 KB |
Output is correct |
40 |
Correct |
35 ms |
15820 KB |
Output is correct |
41 |
Correct |
24 ms |
10580 KB |
Output is correct |
42 |
Correct |
6 ms |
2648 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
1 ms |
344 KB |
Output is correct |
45 |
Correct |
0 ms |
344 KB |
Output is correct |
46 |
Correct |
0 ms |
444 KB |
Output is correct |
47 |
Correct |
0 ms |
344 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
56 ms |
10472 KB |
Output is correct |
58 |
Correct |
49 ms |
10320 KB |
Output is correct |
59 |
Correct |
43 ms |
10320 KB |
Output is correct |
60 |
Correct |
46 ms |
10324 KB |
Output is correct |
61 |
Correct |
43 ms |
10332 KB |
Output is correct |
62 |
Correct |
45 ms |
10324 KB |
Output is correct |
63 |
Correct |
43 ms |
10064 KB |
Output is correct |
64 |
Correct |
38 ms |
10064 KB |
Output is correct |
65 |
Correct |
46 ms |
10440 KB |
Output is correct |
66 |
Correct |
43 ms |
10292 KB |
Output is correct |
67 |
Correct |
44 ms |
10332 KB |
Output is correct |
68 |
Correct |
44 ms |
10376 KB |
Output is correct |
69 |
Correct |
54 ms |
10580 KB |
Output is correct |
70 |
Correct |
45 ms |
10584 KB |
Output is correct |
71 |
Correct |
0 ms |
344 KB |
Output is correct |
72 |
Correct |
1 ms |
604 KB |
Output is correct |
73 |
Correct |
1 ms |
604 KB |
Output is correct |
74 |
Correct |
1 ms |
604 KB |
Output is correct |
75 |
Correct |
1 ms |
500 KB |
Output is correct |
76 |
Correct |
1 ms |
604 KB |
Output is correct |
77 |
Correct |
1 ms |
604 KB |
Output is correct |
78 |
Correct |
1 ms |
604 KB |
Output is correct |
79 |
Correct |
2 ms |
600 KB |
Output is correct |
80 |
Correct |
50 ms |
10288 KB |
Output is correct |
81 |
Correct |
48 ms |
10324 KB |
Output is correct |
82 |
Correct |
46 ms |
10332 KB |
Output is correct |
83 |
Correct |
43 ms |
10320 KB |
Output is correct |
84 |
Correct |
1 ms |
600 KB |
Output is correct |
85 |
Correct |
1 ms |
604 KB |
Output is correct |
86 |
Correct |
1 ms |
604 KB |
Output is correct |
87 |
Correct |
1 ms |
604 KB |
Output is correct |
88 |
Correct |
1 ms |
604 KB |
Output is correct |
89 |
Correct |
1 ms |
604 KB |
Output is correct |
90 |
Correct |
1 ms |
604 KB |
Output is correct |
91 |
Correct |
2 ms |
600 KB |
Output is correct |
92 |
Correct |
2 ms |
604 KB |
Output is correct |
93 |
Correct |
1 ms |
720 KB |
Output is correct |
94 |
Correct |
1 ms |
348 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
1 ms |
348 KB |
Output is correct |
97 |
Correct |
0 ms |
348 KB |
Output is correct |
98 |
Correct |
0 ms |
348 KB |
Output is correct |
99 |
Correct |
0 ms |
348 KB |
Output is correct |
100 |
Correct |
0 ms |
444 KB |
Output is correct |
101 |
Correct |
0 ms |
348 KB |
Output is correct |
102 |
Correct |
0 ms |
348 KB |
Output is correct |
103 |
Correct |
0 ms |
348 KB |
Output is correct |
104 |
Correct |
4 ms |
1628 KB |
Output is correct |
105 |
Correct |
12 ms |
3676 KB |
Output is correct |
106 |
Correct |
1 ms |
348 KB |
Output is correct |
107 |
Correct |
20 ms |
5760 KB |
Output is correct |
108 |
Correct |
28 ms |
7964 KB |
Output is correct |
109 |
Correct |
1 ms |
348 KB |
Output is correct |
110 |
Correct |
36 ms |
10792 KB |
Output is correct |
111 |
Correct |
41 ms |
13144 KB |
Output is correct |
112 |
Correct |
1 ms |
348 KB |
Output is correct |
113 |
Correct |
53 ms |
17492 KB |
Output is correct |
114 |
Correct |
23 ms |
7136 KB |
Output is correct |
115 |
Incorrect |
16 ms |
7128 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |