#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());
ret = max(ret, R[0] + R[1] + L);
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
13564 KB |
Output is correct |
2 |
Correct |
58 ms |
13560 KB |
Output is correct |
3 |
Correct |
47 ms |
10104 KB |
Output is correct |
4 |
Correct |
11 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 |
27 ms |
6776 KB |
Output is correct |
9 |
Correct |
36 ms |
8312 KB |
Output is correct |
10 |
Correct |
5 ms |
3328 KB |
Output is correct |
11 |
Correct |
81 ms |
9836 KB |
Output is correct |
12 |
Correct |
68 ms |
11640 KB |
Output is correct |
13 |
Correct |
5 ms |
3328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
13564 KB |
Output is correct |
2 |
Correct |
58 ms |
13560 KB |
Output is correct |
3 |
Correct |
47 ms |
10104 KB |
Output is correct |
4 |
Correct |
11 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 |
27 ms |
6776 KB |
Output is correct |
9 |
Correct |
36 ms |
8312 KB |
Output is correct |
10 |
Correct |
5 ms |
3328 KB |
Output is correct |
11 |
Correct |
81 ms |
9836 KB |
Output is correct |
12 |
Correct |
68 ms |
11640 KB |
Output is correct |
13 |
Correct |
5 ms |
3328 KB |
Output is correct |
14 |
Correct |
4 ms |
3200 KB |
Output is correct |
15 |
Correct |
4 ms |
3328 KB |
Output is correct |
16 |
Correct |
5 ms |
3200 KB |
Output is correct |
17 |
Correct |
4 ms |
3328 KB |
Output is correct |
18 |
Correct |
5 ms |
3200 KB |
Output is correct |
19 |
Correct |
4 ms |
3200 KB |
Output is correct |
20 |
Correct |
5 ms |
3328 KB |
Output is correct |
21 |
Correct |
4 ms |
3328 KB |
Output is correct |
22 |
Correct |
4 ms |
3328 KB |
Output is correct |
23 |
Correct |
4 ms |
3200 KB |
Output is correct |
24 |
Correct |
5 ms |
3328 KB |
Output is correct |
25 |
Correct |
4 ms |
3200 KB |
Output is correct |
26 |
Correct |
5 ms |
3328 KB |
Output is correct |
27 |
Correct |
4 ms |
3200 KB |
Output is correct |
28 |
Correct |
4 ms |
3200 KB |
Output is correct |
29 |
Correct |
4 ms |
3200 KB |
Output is correct |
30 |
Correct |
5 ms |
3328 KB |
Output is correct |
31 |
Correct |
4 ms |
3328 KB |
Output is correct |
32 |
Correct |
4 ms |
3328 KB |
Output is correct |
33 |
Correct |
4 ms |
3200 KB |
Output is correct |
34 |
Correct |
4 ms |
3328 KB |
Output is correct |
35 |
Correct |
4 ms |
3328 KB |
Output is correct |
36 |
Correct |
4 ms |
3328 KB |
Output is correct |
37 |
Correct |
4 ms |
3328 KB |
Output is correct |
38 |
Correct |
4 ms |
3200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
13564 KB |
Output is correct |
2 |
Correct |
58 ms |
13560 KB |
Output is correct |
3 |
Correct |
47 ms |
10104 KB |
Output is correct |
4 |
Correct |
11 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 |
27 ms |
6776 KB |
Output is correct |
9 |
Correct |
36 ms |
8312 KB |
Output is correct |
10 |
Correct |
5 ms |
3328 KB |
Output is correct |
11 |
Correct |
81 ms |
9836 KB |
Output is correct |
12 |
Correct |
68 ms |
11640 KB |
Output is correct |
13 |
Correct |
5 ms |
3328 KB |
Output is correct |
14 |
Correct |
4 ms |
3200 KB |
Output is correct |
15 |
Correct |
4 ms |
3328 KB |
Output is correct |
16 |
Correct |
5 ms |
3200 KB |
Output is correct |
17 |
Correct |
4 ms |
3328 KB |
Output is correct |
18 |
Correct |
5 ms |
3200 KB |
Output is correct |
19 |
Correct |
4 ms |
3200 KB |
Output is correct |
20 |
Correct |
5 ms |
3328 KB |
Output is correct |
21 |
Correct |
4 ms |
3328 KB |
Output is correct |
22 |
Correct |
4 ms |
3328 KB |
Output is correct |
23 |
Correct |
4 ms |
3200 KB |
Output is correct |
24 |
Correct |
5 ms |
3328 KB |
Output is correct |
25 |
Correct |
4 ms |
3200 KB |
Output is correct |
26 |
Correct |
5 ms |
3328 KB |
Output is correct |
27 |
Correct |
4 ms |
3200 KB |
Output is correct |
28 |
Correct |
4 ms |
3200 KB |
Output is correct |
29 |
Correct |
4 ms |
3200 KB |
Output is correct |
30 |
Correct |
5 ms |
3328 KB |
Output is correct |
31 |
Correct |
4 ms |
3328 KB |
Output is correct |
32 |
Correct |
4 ms |
3328 KB |
Output is correct |
33 |
Correct |
4 ms |
3200 KB |
Output is correct |
34 |
Correct |
4 ms |
3328 KB |
Output is correct |
35 |
Correct |
4 ms |
3328 KB |
Output is correct |
36 |
Correct |
4 ms |
3328 KB |
Output is correct |
37 |
Correct |
4 ms |
3328 KB |
Output is correct |
38 |
Correct |
4 ms |
3200 KB |
Output is correct |
39 |
Correct |
72 ms |
13588 KB |
Output is correct |
40 |
Correct |
70 ms |
13532 KB |
Output is correct |
41 |
Correct |
41 ms |
10104 KB |
Output is correct |
42 |
Correct |
12 ms |
4736 KB |
Output is correct |
43 |
Correct |
4 ms |
3328 KB |
Output is correct |
44 |
Correct |
4 ms |
3328 KB |
Output is correct |
45 |
Correct |
5 ms |
3308 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 |
3328 KB |
Output is correct |
49 |
Correct |
4 ms |
3328 KB |
Output is correct |
50 |
Correct |
4 ms |
3328 KB |
Output is correct |
51 |
Correct |
5 ms |
3328 KB |
Output is correct |
52 |
Correct |
4 ms |
3328 KB |
Output is correct |
53 |
Correct |
5 ms |
3328 KB |
Output is correct |
54 |
Correct |
4 ms |
3200 KB |
Output is correct |
55 |
Correct |
4 ms |
3200 KB |
Output is correct |
56 |
Correct |
4 ms |
3200 KB |
Output is correct |
57 |
Correct |
93 ms |
9208 KB |
Output is correct |
58 |
Correct |
62 ms |
9180 KB |
Output is correct |
59 |
Correct |
66 ms |
9208 KB |
Output is correct |
60 |
Correct |
69 ms |
9208 KB |
Output is correct |
61 |
Correct |
73 ms |
9052 KB |
Output is correct |
62 |
Correct |
61 ms |
8952 KB |
Output is correct |
63 |
Correct |
66 ms |
8824 KB |
Output is correct |
64 |
Correct |
62 ms |
8828 KB |
Output is correct |
65 |
Correct |
78 ms |
8824 KB |
Output is correct |
66 |
Correct |
62 ms |
8824 KB |
Output is correct |
67 |
Correct |
80 ms |
9080 KB |
Output is correct |
68 |
Correct |
64 ms |
9180 KB |
Output is correct |
69 |
Correct |
79 ms |
9148 KB |
Output is correct |
70 |
Correct |
76 ms |
9084 KB |
Output is correct |
71 |
Correct |
4 ms |
3200 KB |
Output is correct |
72 |
Correct |
5 ms |
3456 KB |
Output is correct |
73 |
Correct |
5 ms |
3456 KB |
Output is correct |
74 |
Correct |
7 ms |
3456 KB |
Output is correct |
75 |
Correct |
5 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 |
6 ms |
3456 KB |
Output is correct |
79 |
Correct |
6 ms |
3456 KB |
Output is correct |
80 |
Correct |
94 ms |
9080 KB |
Output is correct |
81 |
Correct |
81 ms |
9080 KB |
Output is correct |
82 |
Correct |
93 ms |
9084 KB |
Output is correct |
83 |
Correct |
90 ms |
9116 KB |
Output is correct |
84 |
Correct |
5 ms |
3328 KB |
Output is correct |
85 |
Correct |
7 ms |
3372 KB |
Output is correct |
86 |
Correct |
6 ms |
3456 KB |
Output is correct |
87 |
Correct |
5 ms |
3328 KB |
Output is correct |
88 |
Correct |
5 ms |
3328 KB |
Output is correct |
89 |
Correct |
5 ms |
3328 KB |
Output is correct |
90 |
Correct |
6 ms |
3456 KB |
Output is correct |
91 |
Correct |
7 ms |
3456 KB |
Output is correct |
92 |
Correct |
5 ms |
3328 KB |
Output is correct |
93 |
Correct |
6 ms |
3456 KB |
Output is correct |
94 |
Correct |
4 ms |
3328 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 |
3328 KB |
Output is correct |
103 |
Correct |
4 ms |
3200 KB |
Output is correct |
104 |
Correct |
10 ms |
4096 KB |
Output is correct |
105 |
Correct |
16 ms |
5504 KB |
Output is correct |
106 |
Correct |
5 ms |
3328 KB |
Output is correct |
107 |
Correct |
31 ms |
6776 KB |
Output is correct |
108 |
Correct |
37 ms |
8312 KB |
Output is correct |
109 |
Correct |
4 ms |
3328 KB |
Output is correct |
110 |
Correct |
57 ms |
9724 KB |
Output is correct |
111 |
Correct |
63 ms |
11640 KB |
Output is correct |
112 |
Correct |
4 ms |
3328 KB |
Output is correct |
113 |
Correct |
95 ms |
14584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
6648 KB |
Output is correct |
2 |
Incorrect |
29 ms |
6700 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
13564 KB |
Output is correct |
2 |
Correct |
58 ms |
13560 KB |
Output is correct |
3 |
Correct |
47 ms |
10104 KB |
Output is correct |
4 |
Correct |
11 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 |
27 ms |
6776 KB |
Output is correct |
9 |
Correct |
36 ms |
8312 KB |
Output is correct |
10 |
Correct |
5 ms |
3328 KB |
Output is correct |
11 |
Correct |
81 ms |
9836 KB |
Output is correct |
12 |
Correct |
68 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 |
5 ms |
3328 KB |
Output is correct |
16 |
Correct |
5 ms |
3456 KB |
Output is correct |
17 |
Correct |
5 ms |
3328 KB |
Output is correct |
18 |
Correct |
5 ms |
3328 KB |
Output is correct |
19 |
Correct |
5 ms |
3456 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 |
64 ms |
13564 KB |
Output is correct |
2 |
Correct |
58 ms |
13560 KB |
Output is correct |
3 |
Correct |
47 ms |
10104 KB |
Output is correct |
4 |
Correct |
11 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 |
27 ms |
6776 KB |
Output is correct |
9 |
Correct |
36 ms |
8312 KB |
Output is correct |
10 |
Correct |
5 ms |
3328 KB |
Output is correct |
11 |
Correct |
81 ms |
9836 KB |
Output is correct |
12 |
Correct |
68 ms |
11640 KB |
Output is correct |
13 |
Correct |
5 ms |
3328 KB |
Output is correct |
14 |
Correct |
4 ms |
3200 KB |
Output is correct |
15 |
Correct |
4 ms |
3328 KB |
Output is correct |
16 |
Correct |
5 ms |
3200 KB |
Output is correct |
17 |
Correct |
4 ms |
3328 KB |
Output is correct |
18 |
Correct |
5 ms |
3200 KB |
Output is correct |
19 |
Correct |
4 ms |
3200 KB |
Output is correct |
20 |
Correct |
5 ms |
3328 KB |
Output is correct |
21 |
Correct |
4 ms |
3328 KB |
Output is correct |
22 |
Correct |
4 ms |
3328 KB |
Output is correct |
23 |
Correct |
4 ms |
3200 KB |
Output is correct |
24 |
Correct |
5 ms |
3328 KB |
Output is correct |
25 |
Correct |
4 ms |
3200 KB |
Output is correct |
26 |
Correct |
5 ms |
3328 KB |
Output is correct |
27 |
Correct |
4 ms |
3200 KB |
Output is correct |
28 |
Correct |
4 ms |
3200 KB |
Output is correct |
29 |
Correct |
4 ms |
3200 KB |
Output is correct |
30 |
Correct |
5 ms |
3328 KB |
Output is correct |
31 |
Correct |
4 ms |
3328 KB |
Output is correct |
32 |
Correct |
4 ms |
3328 KB |
Output is correct |
33 |
Correct |
4 ms |
3200 KB |
Output is correct |
34 |
Correct |
4 ms |
3328 KB |
Output is correct |
35 |
Correct |
4 ms |
3328 KB |
Output is correct |
36 |
Correct |
4 ms |
3328 KB |
Output is correct |
37 |
Correct |
4 ms |
3328 KB |
Output is correct |
38 |
Correct |
4 ms |
3200 KB |
Output is correct |
39 |
Correct |
72 ms |
13588 KB |
Output is correct |
40 |
Correct |
70 ms |
13532 KB |
Output is correct |
41 |
Correct |
41 ms |
10104 KB |
Output is correct |
42 |
Correct |
12 ms |
4736 KB |
Output is correct |
43 |
Correct |
4 ms |
3328 KB |
Output is correct |
44 |
Correct |
4 ms |
3328 KB |
Output is correct |
45 |
Correct |
5 ms |
3308 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 |
3328 KB |
Output is correct |
49 |
Correct |
4 ms |
3328 KB |
Output is correct |
50 |
Correct |
4 ms |
3328 KB |
Output is correct |
51 |
Correct |
5 ms |
3328 KB |
Output is correct |
52 |
Correct |
4 ms |
3328 KB |
Output is correct |
53 |
Correct |
5 ms |
3328 KB |
Output is correct |
54 |
Correct |
4 ms |
3200 KB |
Output is correct |
55 |
Correct |
4 ms |
3200 KB |
Output is correct |
56 |
Correct |
4 ms |
3200 KB |
Output is correct |
57 |
Correct |
93 ms |
9208 KB |
Output is correct |
58 |
Correct |
62 ms |
9180 KB |
Output is correct |
59 |
Correct |
66 ms |
9208 KB |
Output is correct |
60 |
Correct |
69 ms |
9208 KB |
Output is correct |
61 |
Correct |
73 ms |
9052 KB |
Output is correct |
62 |
Correct |
61 ms |
8952 KB |
Output is correct |
63 |
Correct |
66 ms |
8824 KB |
Output is correct |
64 |
Correct |
62 ms |
8828 KB |
Output is correct |
65 |
Correct |
78 ms |
8824 KB |
Output is correct |
66 |
Correct |
62 ms |
8824 KB |
Output is correct |
67 |
Correct |
80 ms |
9080 KB |
Output is correct |
68 |
Correct |
64 ms |
9180 KB |
Output is correct |
69 |
Correct |
79 ms |
9148 KB |
Output is correct |
70 |
Correct |
76 ms |
9084 KB |
Output is correct |
71 |
Correct |
4 ms |
3200 KB |
Output is correct |
72 |
Correct |
5 ms |
3456 KB |
Output is correct |
73 |
Correct |
5 ms |
3456 KB |
Output is correct |
74 |
Correct |
7 ms |
3456 KB |
Output is correct |
75 |
Correct |
5 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 |
6 ms |
3456 KB |
Output is correct |
79 |
Correct |
6 ms |
3456 KB |
Output is correct |
80 |
Correct |
94 ms |
9080 KB |
Output is correct |
81 |
Correct |
81 ms |
9080 KB |
Output is correct |
82 |
Correct |
93 ms |
9084 KB |
Output is correct |
83 |
Correct |
90 ms |
9116 KB |
Output is correct |
84 |
Correct |
5 ms |
3328 KB |
Output is correct |
85 |
Correct |
7 ms |
3372 KB |
Output is correct |
86 |
Correct |
6 ms |
3456 KB |
Output is correct |
87 |
Correct |
5 ms |
3328 KB |
Output is correct |
88 |
Correct |
5 ms |
3328 KB |
Output is correct |
89 |
Correct |
5 ms |
3328 KB |
Output is correct |
90 |
Correct |
6 ms |
3456 KB |
Output is correct |
91 |
Correct |
7 ms |
3456 KB |
Output is correct |
92 |
Correct |
5 ms |
3328 KB |
Output is correct |
93 |
Correct |
6 ms |
3456 KB |
Output is correct |
94 |
Correct |
4 ms |
3328 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 |
3328 KB |
Output is correct |
103 |
Correct |
4 ms |
3200 KB |
Output is correct |
104 |
Correct |
10 ms |
4096 KB |
Output is correct |
105 |
Correct |
16 ms |
5504 KB |
Output is correct |
106 |
Correct |
5 ms |
3328 KB |
Output is correct |
107 |
Correct |
31 ms |
6776 KB |
Output is correct |
108 |
Correct |
37 ms |
8312 KB |
Output is correct |
109 |
Correct |
4 ms |
3328 KB |
Output is correct |
110 |
Correct |
57 ms |
9724 KB |
Output is correct |
111 |
Correct |
63 ms |
11640 KB |
Output is correct |
112 |
Correct |
4 ms |
3328 KB |
Output is correct |
113 |
Correct |
95 ms |
14584 KB |
Output is correct |
114 |
Correct |
27 ms |
6648 KB |
Output is correct |
115 |
Incorrect |
29 ms |
6700 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |