#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
typedef pair <int, int> edge;
#define to first
#define cost second
const int MAX = 123456;
bitset <MAX> vis;
vector <edge> g[MAX];
int maxDist, at;
edge par[MAX];
void dfs (int u, int from, int far, int flag) {
if (flag) {
vis[u] = 1;
}
if (far > maxDist) {
maxDist = far;
at = u;
}
for (edge e : g[u]) {
if (e.to == from) continue;
if (flag) {
par[e.to] = edge(u, e.cost);
}
dfs(e.to, u, far + e.cost, flag);
}
}
int travelTime (int N, int M, int L, int A[], int B[], int T[]) {
for (int i = 0; i < M; ++i) {
g[A[i]].emplace_back(B[i], T[i]);
g[B[i]].emplace_back(A[i], T[i]);
}
vector <int> R;
int ret = 0;
for (int i = 0; i < N; ++i) {
if (vis[i]) continue;
maxDist = -1;
dfs(i, i, 0, 0);
int one = at;
maxDist = -1;
dfs(one, one, 0, 1);
int two = at;
ret = max(ret, maxDist);
int half = maxDist >> 1;
int radius = 0;
for (int v = two; v != one; v = par[v].to) {
radius += par[v].cost;
if (radius > half) {
radius = min(radius, maxDist - radius + par[v].cost);
break;
}
}
R.push_back(radius);
}
sort(R.rbegin(), R.rend());
if (R.size() > 1) ret = max(ret, R[0] + R[1] + L);
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
13560 KB |
Output is correct |
2 |
Correct |
57 ms |
13560 KB |
Output is correct |
3 |
Correct |
40 ms |
10104 KB |
Output is correct |
4 |
Correct |
12 ms |
4736 KB |
Output is correct |
5 |
Correct |
10 ms |
4096 KB |
Output is correct |
6 |
Correct |
17 ms |
5504 KB |
Output is correct |
7 |
Correct |
4 ms |
3200 KB |
Output is correct |
8 |
Correct |
29 ms |
6776 KB |
Output is correct |
9 |
Correct |
37 ms |
8312 KB |
Output is correct |
10 |
Correct |
4 ms |
3328 KB |
Output is correct |
11 |
Correct |
56 ms |
9848 KB |
Output is correct |
12 |
Correct |
59 ms |
11640 KB |
Output is correct |
13 |
Correct |
5 ms |
3328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
13560 KB |
Output is correct |
2 |
Correct |
57 ms |
13560 KB |
Output is correct |
3 |
Correct |
40 ms |
10104 KB |
Output is correct |
4 |
Correct |
12 ms |
4736 KB |
Output is correct |
5 |
Correct |
10 ms |
4096 KB |
Output is correct |
6 |
Correct |
17 ms |
5504 KB |
Output is correct |
7 |
Correct |
4 ms |
3200 KB |
Output is correct |
8 |
Correct |
29 ms |
6776 KB |
Output is correct |
9 |
Correct |
37 ms |
8312 KB |
Output is correct |
10 |
Correct |
4 ms |
3328 KB |
Output is correct |
11 |
Correct |
56 ms |
9848 KB |
Output is correct |
12 |
Correct |
59 ms |
11640 KB |
Output is correct |
13 |
Correct |
5 ms |
3328 KB |
Output is correct |
14 |
Correct |
4 ms |
3328 KB |
Output is correct |
15 |
Correct |
4 ms |
3200 KB |
Output is correct |
16 |
Correct |
4 ms |
3200 KB |
Output is correct |
17 |
Correct |
4 ms |
3200 KB |
Output is correct |
18 |
Correct |
5 ms |
3328 KB |
Output is correct |
19 |
Correct |
4 ms |
3328 KB |
Output is correct |
20 |
Correct |
4 ms |
3328 KB |
Output is correct |
21 |
Correct |
4 ms |
3328 KB |
Output is correct |
22 |
Correct |
5 ms |
3328 KB |
Output is correct |
23 |
Correct |
4 ms |
3328 KB |
Output is correct |
24 |
Correct |
4 ms |
3200 KB |
Output is correct |
25 |
Correct |
4 ms |
3328 KB |
Output is correct |
26 |
Correct |
4 ms |
3328 KB |
Output is correct |
27 |
Correct |
5 ms |
3200 KB |
Output is correct |
28 |
Correct |
5 ms |
3200 KB |
Output is correct |
29 |
Correct |
5 ms |
3200 KB |
Output is correct |
30 |
Correct |
6 ms |
3328 KB |
Output is correct |
31 |
Correct |
1 ms |
3328 KB |
Output is correct |
32 |
Correct |
5 ms |
3328 KB |
Output is correct |
33 |
Correct |
4 ms |
3328 KB |
Output is correct |
34 |
Correct |
4 ms |
3328 KB |
Output is correct |
35 |
Correct |
4 ms |
3200 KB |
Output is correct |
36 |
Correct |
5 ms |
3328 KB |
Output is correct |
37 |
Correct |
6 ms |
3328 KB |
Output is correct |
38 |
Correct |
5 ms |
3328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
13560 KB |
Output is correct |
2 |
Correct |
57 ms |
13560 KB |
Output is correct |
3 |
Correct |
40 ms |
10104 KB |
Output is correct |
4 |
Correct |
12 ms |
4736 KB |
Output is correct |
5 |
Correct |
10 ms |
4096 KB |
Output is correct |
6 |
Correct |
17 ms |
5504 KB |
Output is correct |
7 |
Correct |
4 ms |
3200 KB |
Output is correct |
8 |
Correct |
29 ms |
6776 KB |
Output is correct |
9 |
Correct |
37 ms |
8312 KB |
Output is correct |
10 |
Correct |
4 ms |
3328 KB |
Output is correct |
11 |
Correct |
56 ms |
9848 KB |
Output is correct |
12 |
Correct |
59 ms |
11640 KB |
Output is correct |
13 |
Correct |
5 ms |
3328 KB |
Output is correct |
14 |
Correct |
4 ms |
3328 KB |
Output is correct |
15 |
Correct |
4 ms |
3200 KB |
Output is correct |
16 |
Correct |
4 ms |
3200 KB |
Output is correct |
17 |
Correct |
4 ms |
3200 KB |
Output is correct |
18 |
Correct |
5 ms |
3328 KB |
Output is correct |
19 |
Correct |
4 ms |
3328 KB |
Output is correct |
20 |
Correct |
4 ms |
3328 KB |
Output is correct |
21 |
Correct |
4 ms |
3328 KB |
Output is correct |
22 |
Correct |
5 ms |
3328 KB |
Output is correct |
23 |
Correct |
4 ms |
3328 KB |
Output is correct |
24 |
Correct |
4 ms |
3200 KB |
Output is correct |
25 |
Correct |
4 ms |
3328 KB |
Output is correct |
26 |
Correct |
4 ms |
3328 KB |
Output is correct |
27 |
Correct |
5 ms |
3200 KB |
Output is correct |
28 |
Correct |
5 ms |
3200 KB |
Output is correct |
29 |
Correct |
5 ms |
3200 KB |
Output is correct |
30 |
Correct |
6 ms |
3328 KB |
Output is correct |
31 |
Correct |
1 ms |
3328 KB |
Output is correct |
32 |
Correct |
5 ms |
3328 KB |
Output is correct |
33 |
Correct |
4 ms |
3328 KB |
Output is correct |
34 |
Correct |
4 ms |
3328 KB |
Output is correct |
35 |
Correct |
4 ms |
3200 KB |
Output is correct |
36 |
Correct |
5 ms |
3328 KB |
Output is correct |
37 |
Correct |
6 ms |
3328 KB |
Output is correct |
38 |
Correct |
5 ms |
3328 KB |
Output is correct |
39 |
Correct |
57 ms |
13560 KB |
Output is correct |
40 |
Correct |
68 ms |
13540 KB |
Output is correct |
41 |
Correct |
43 ms |
10104 KB |
Output is correct |
42 |
Correct |
11 ms |
4736 KB |
Output is correct |
43 |
Correct |
7 ms |
3200 KB |
Output is correct |
44 |
Correct |
4 ms |
3328 KB |
Output is correct |
45 |
Correct |
4 ms |
3200 KB |
Output is correct |
46 |
Correct |
4 ms |
3328 KB |
Output is correct |
47 |
Correct |
4 ms |
3328 KB |
Output is correct |
48 |
Correct |
4 ms |
3200 KB |
Output is correct |
49 |
Correct |
4 ms |
3196 KB |
Output is correct |
50 |
Correct |
4 ms |
3328 KB |
Output is correct |
51 |
Correct |
7 ms |
3200 KB |
Output is correct |
52 |
Correct |
5 ms |
3200 KB |
Output is correct |
53 |
Correct |
5 ms |
3328 KB |
Output is correct |
54 |
Correct |
4 ms |
3404 KB |
Output is correct |
55 |
Correct |
4 ms |
3328 KB |
Output is correct |
56 |
Correct |
4 ms |
3200 KB |
Output is correct |
57 |
Correct |
78 ms |
9208 KB |
Output is correct |
58 |
Correct |
70 ms |
9208 KB |
Output is correct |
59 |
Correct |
91 ms |
9216 KB |
Output is correct |
60 |
Correct |
72 ms |
9208 KB |
Output is correct |
61 |
Correct |
71 ms |
9096 KB |
Output is correct |
62 |
Correct |
70 ms |
9080 KB |
Output is correct |
63 |
Correct |
62 ms |
8956 KB |
Output is correct |
64 |
Correct |
64 ms |
8952 KB |
Output is correct |
65 |
Correct |
64 ms |
8952 KB |
Output is correct |
66 |
Correct |
65 ms |
8824 KB |
Output is correct |
67 |
Correct |
85 ms |
9128 KB |
Output is correct |
68 |
Correct |
87 ms |
9080 KB |
Output is correct |
69 |
Correct |
81 ms |
9208 KB |
Output is correct |
70 |
Correct |
112 ms |
9180 KB |
Output is correct |
71 |
Correct |
5 ms |
3200 KB |
Output is correct |
72 |
Correct |
6 ms |
3456 KB |
Output is correct |
73 |
Correct |
5 ms |
3456 KB |
Output is correct |
74 |
Correct |
5 ms |
3456 KB |
Output is correct |
75 |
Correct |
6 ms |
3456 KB |
Output is correct |
76 |
Correct |
6 ms |
3456 KB |
Output is correct |
77 |
Correct |
6 ms |
3456 KB |
Output is correct |
78 |
Correct |
5 ms |
3456 KB |
Output is correct |
79 |
Correct |
6 ms |
3456 KB |
Output is correct |
80 |
Correct |
73 ms |
9052 KB |
Output is correct |
81 |
Correct |
90 ms |
9040 KB |
Output is correct |
82 |
Correct |
72 ms |
9052 KB |
Output is correct |
83 |
Correct |
68 ms |
8996 KB |
Output is correct |
84 |
Correct |
5 ms |
3456 KB |
Output is correct |
85 |
Correct |
5 ms |
3328 KB |
Output is correct |
86 |
Correct |
5 ms |
3328 KB |
Output is correct |
87 |
Correct |
6 ms |
3456 KB |
Output is correct |
88 |
Correct |
5 ms |
3456 KB |
Output is correct |
89 |
Correct |
5 ms |
3328 KB |
Output is correct |
90 |
Correct |
5 ms |
3456 KB |
Output is correct |
91 |
Correct |
5 ms |
3456 KB |
Output is correct |
92 |
Correct |
5 ms |
3328 KB |
Output is correct |
93 |
Correct |
5 ms |
3456 KB |
Output is correct |
94 |
Correct |
4 ms |
3200 KB |
Output is correct |
95 |
Correct |
4 ms |
3200 KB |
Output is correct |
96 |
Correct |
4 ms |
3200 KB |
Output is correct |
97 |
Correct |
4 ms |
3200 KB |
Output is correct |
98 |
Correct |
4 ms |
3200 KB |
Output is correct |
99 |
Correct |
4 ms |
3200 KB |
Output is correct |
100 |
Correct |
4 ms |
3200 KB |
Output is correct |
101 |
Correct |
4 ms |
3200 KB |
Output is correct |
102 |
Correct |
4 ms |
3200 KB |
Output is correct |
103 |
Correct |
4 ms |
3328 KB |
Output is correct |
104 |
Correct |
10 ms |
4096 KB |
Output is correct |
105 |
Correct |
17 ms |
5504 KB |
Output is correct |
106 |
Correct |
5 ms |
3328 KB |
Output is correct |
107 |
Correct |
31 ms |
6828 KB |
Output is correct |
108 |
Correct |
38 ms |
8312 KB |
Output is correct |
109 |
Correct |
5 ms |
3328 KB |
Output is correct |
110 |
Correct |
55 ms |
9848 KB |
Output is correct |
111 |
Correct |
56 ms |
11640 KB |
Output is correct |
112 |
Correct |
5 ms |
3328 KB |
Output is correct |
113 |
Correct |
108 ms |
14656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
6648 KB |
Output is correct |
2 |
Incorrect |
27 ms |
6648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
13560 KB |
Output is correct |
2 |
Correct |
57 ms |
13560 KB |
Output is correct |
3 |
Correct |
40 ms |
10104 KB |
Output is correct |
4 |
Correct |
12 ms |
4736 KB |
Output is correct |
5 |
Correct |
10 ms |
4096 KB |
Output is correct |
6 |
Correct |
17 ms |
5504 KB |
Output is correct |
7 |
Correct |
4 ms |
3200 KB |
Output is correct |
8 |
Correct |
29 ms |
6776 KB |
Output is correct |
9 |
Correct |
37 ms |
8312 KB |
Output is correct |
10 |
Correct |
4 ms |
3328 KB |
Output is correct |
11 |
Correct |
56 ms |
9848 KB |
Output is correct |
12 |
Correct |
59 ms |
11640 KB |
Output is correct |
13 |
Correct |
5 ms |
3328 KB |
Output is correct |
14 |
Correct |
4 ms |
3328 KB |
Output is correct |
15 |
Correct |
4 ms |
3328 KB |
Output is correct |
16 |
Correct |
6 ms |
3328 KB |
Output is correct |
17 |
Correct |
4 ms |
3328 KB |
Output is correct |
18 |
Correct |
5 ms |
3328 KB |
Output is correct |
19 |
Correct |
5 ms |
3328 KB |
Output is correct |
20 |
Incorrect |
4 ms |
3328 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
13560 KB |
Output is correct |
2 |
Correct |
57 ms |
13560 KB |
Output is correct |
3 |
Correct |
40 ms |
10104 KB |
Output is correct |
4 |
Correct |
12 ms |
4736 KB |
Output is correct |
5 |
Correct |
10 ms |
4096 KB |
Output is correct |
6 |
Correct |
17 ms |
5504 KB |
Output is correct |
7 |
Correct |
4 ms |
3200 KB |
Output is correct |
8 |
Correct |
29 ms |
6776 KB |
Output is correct |
9 |
Correct |
37 ms |
8312 KB |
Output is correct |
10 |
Correct |
4 ms |
3328 KB |
Output is correct |
11 |
Correct |
56 ms |
9848 KB |
Output is correct |
12 |
Correct |
59 ms |
11640 KB |
Output is correct |
13 |
Correct |
5 ms |
3328 KB |
Output is correct |
14 |
Correct |
4 ms |
3328 KB |
Output is correct |
15 |
Correct |
4 ms |
3200 KB |
Output is correct |
16 |
Correct |
4 ms |
3200 KB |
Output is correct |
17 |
Correct |
4 ms |
3200 KB |
Output is correct |
18 |
Correct |
5 ms |
3328 KB |
Output is correct |
19 |
Correct |
4 ms |
3328 KB |
Output is correct |
20 |
Correct |
4 ms |
3328 KB |
Output is correct |
21 |
Correct |
4 ms |
3328 KB |
Output is correct |
22 |
Correct |
5 ms |
3328 KB |
Output is correct |
23 |
Correct |
4 ms |
3328 KB |
Output is correct |
24 |
Correct |
4 ms |
3200 KB |
Output is correct |
25 |
Correct |
4 ms |
3328 KB |
Output is correct |
26 |
Correct |
4 ms |
3328 KB |
Output is correct |
27 |
Correct |
5 ms |
3200 KB |
Output is correct |
28 |
Correct |
5 ms |
3200 KB |
Output is correct |
29 |
Correct |
5 ms |
3200 KB |
Output is correct |
30 |
Correct |
6 ms |
3328 KB |
Output is correct |
31 |
Correct |
1 ms |
3328 KB |
Output is correct |
32 |
Correct |
5 ms |
3328 KB |
Output is correct |
33 |
Correct |
4 ms |
3328 KB |
Output is correct |
34 |
Correct |
4 ms |
3328 KB |
Output is correct |
35 |
Correct |
4 ms |
3200 KB |
Output is correct |
36 |
Correct |
5 ms |
3328 KB |
Output is correct |
37 |
Correct |
6 ms |
3328 KB |
Output is correct |
38 |
Correct |
5 ms |
3328 KB |
Output is correct |
39 |
Correct |
57 ms |
13560 KB |
Output is correct |
40 |
Correct |
68 ms |
13540 KB |
Output is correct |
41 |
Correct |
43 ms |
10104 KB |
Output is correct |
42 |
Correct |
11 ms |
4736 KB |
Output is correct |
43 |
Correct |
7 ms |
3200 KB |
Output is correct |
44 |
Correct |
4 ms |
3328 KB |
Output is correct |
45 |
Correct |
4 ms |
3200 KB |
Output is correct |
46 |
Correct |
4 ms |
3328 KB |
Output is correct |
47 |
Correct |
4 ms |
3328 KB |
Output is correct |
48 |
Correct |
4 ms |
3200 KB |
Output is correct |
49 |
Correct |
4 ms |
3196 KB |
Output is correct |
50 |
Correct |
4 ms |
3328 KB |
Output is correct |
51 |
Correct |
7 ms |
3200 KB |
Output is correct |
52 |
Correct |
5 ms |
3200 KB |
Output is correct |
53 |
Correct |
5 ms |
3328 KB |
Output is correct |
54 |
Correct |
4 ms |
3404 KB |
Output is correct |
55 |
Correct |
4 ms |
3328 KB |
Output is correct |
56 |
Correct |
4 ms |
3200 KB |
Output is correct |
57 |
Correct |
78 ms |
9208 KB |
Output is correct |
58 |
Correct |
70 ms |
9208 KB |
Output is correct |
59 |
Correct |
91 ms |
9216 KB |
Output is correct |
60 |
Correct |
72 ms |
9208 KB |
Output is correct |
61 |
Correct |
71 ms |
9096 KB |
Output is correct |
62 |
Correct |
70 ms |
9080 KB |
Output is correct |
63 |
Correct |
62 ms |
8956 KB |
Output is correct |
64 |
Correct |
64 ms |
8952 KB |
Output is correct |
65 |
Correct |
64 ms |
8952 KB |
Output is correct |
66 |
Correct |
65 ms |
8824 KB |
Output is correct |
67 |
Correct |
85 ms |
9128 KB |
Output is correct |
68 |
Correct |
87 ms |
9080 KB |
Output is correct |
69 |
Correct |
81 ms |
9208 KB |
Output is correct |
70 |
Correct |
112 ms |
9180 KB |
Output is correct |
71 |
Correct |
5 ms |
3200 KB |
Output is correct |
72 |
Correct |
6 ms |
3456 KB |
Output is correct |
73 |
Correct |
5 ms |
3456 KB |
Output is correct |
74 |
Correct |
5 ms |
3456 KB |
Output is correct |
75 |
Correct |
6 ms |
3456 KB |
Output is correct |
76 |
Correct |
6 ms |
3456 KB |
Output is correct |
77 |
Correct |
6 ms |
3456 KB |
Output is correct |
78 |
Correct |
5 ms |
3456 KB |
Output is correct |
79 |
Correct |
6 ms |
3456 KB |
Output is correct |
80 |
Correct |
73 ms |
9052 KB |
Output is correct |
81 |
Correct |
90 ms |
9040 KB |
Output is correct |
82 |
Correct |
72 ms |
9052 KB |
Output is correct |
83 |
Correct |
68 ms |
8996 KB |
Output is correct |
84 |
Correct |
5 ms |
3456 KB |
Output is correct |
85 |
Correct |
5 ms |
3328 KB |
Output is correct |
86 |
Correct |
5 ms |
3328 KB |
Output is correct |
87 |
Correct |
6 ms |
3456 KB |
Output is correct |
88 |
Correct |
5 ms |
3456 KB |
Output is correct |
89 |
Correct |
5 ms |
3328 KB |
Output is correct |
90 |
Correct |
5 ms |
3456 KB |
Output is correct |
91 |
Correct |
5 ms |
3456 KB |
Output is correct |
92 |
Correct |
5 ms |
3328 KB |
Output is correct |
93 |
Correct |
5 ms |
3456 KB |
Output is correct |
94 |
Correct |
4 ms |
3200 KB |
Output is correct |
95 |
Correct |
4 ms |
3200 KB |
Output is correct |
96 |
Correct |
4 ms |
3200 KB |
Output is correct |
97 |
Correct |
4 ms |
3200 KB |
Output is correct |
98 |
Correct |
4 ms |
3200 KB |
Output is correct |
99 |
Correct |
4 ms |
3200 KB |
Output is correct |
100 |
Correct |
4 ms |
3200 KB |
Output is correct |
101 |
Correct |
4 ms |
3200 KB |
Output is correct |
102 |
Correct |
4 ms |
3200 KB |
Output is correct |
103 |
Correct |
4 ms |
3328 KB |
Output is correct |
104 |
Correct |
10 ms |
4096 KB |
Output is correct |
105 |
Correct |
17 ms |
5504 KB |
Output is correct |
106 |
Correct |
5 ms |
3328 KB |
Output is correct |
107 |
Correct |
31 ms |
6828 KB |
Output is correct |
108 |
Correct |
38 ms |
8312 KB |
Output is correct |
109 |
Correct |
5 ms |
3328 KB |
Output is correct |
110 |
Correct |
55 ms |
9848 KB |
Output is correct |
111 |
Correct |
56 ms |
11640 KB |
Output is correct |
112 |
Correct |
5 ms |
3328 KB |
Output is correct |
113 |
Correct |
108 ms |
14656 KB |
Output is correct |
114 |
Correct |
30 ms |
6648 KB |
Output is correct |
115 |
Incorrect |
27 ms |
6648 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |