#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
vector<pair<int, int>> adj[N];
vector<int> nodes;
int it, up[N], down[N][2], radius[N], res; bool dd[N];
void calc_down(int x, int par) {
nodes.push_back(x); dd[x] = 1;
for (pair<int, int> v : adj[x]) if (v.first != par) {
int i, w; tie(i, w) = v;
calc_down(i, x);
if (down[i][0] + w > down[x][0]) {
down[x][1] = down[x][0];
down[x][0] = down[i][0] + w;
}
else if (down[i][0] + w > down[x][1]) down[x][1] = down[i][0] + w;
}
}
void calc_up(int x, int par) {
for (pair<int, int> v : adj[x]) if (v.first != par) {
int i, w; tie(i, w) = v;
up[i] = up[x] + w;
if (down[i][0] + w == down[x][0]) up[i] = max(up[i], down[x][1] + w);
else up[i] = max(up[i], down[x][0] + w);
calc_up(i, x);
}
radius[it] = min(radius[it], max(up[x], down[x][0]));
res = max(res, up[x] + down[x][0]);
}
int travelTime(int n, int m, int l, int x[], int y[], int w[]) {
for (int i = 0; i < m; ++i) {
++x[i]; ++y[i];
adj[x[i]].push_back(make_pair(y[i], w[i]));
adj[y[i]].push_back(make_pair(x[i], w[i]));
}
for (int i = 1; i <= n; ++i) if (!dd[i]) {
++it; nodes.clear();
radius[it] = 2e9;
calc_down(i, 0);
calc_up(i, 0);
}
sort(radius + 1, radius + it + 1, greater<int>());
if (it > 1) res = max(res, radius[1] + radius[2] + l);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
13388 KB |
Output is correct |
2 |
Correct |
47 ms |
13100 KB |
Output is correct |
3 |
Correct |
29 ms |
11292 KB |
Output is correct |
4 |
Correct |
7 ms |
4224 KB |
Output is correct |
5 |
Correct |
6 ms |
3532 KB |
Output is correct |
6 |
Correct |
11 ms |
5076 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
22 ms |
7128 KB |
Output is correct |
9 |
Correct |
34 ms |
9396 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
40 ms |
10624 KB |
Output is correct |
12 |
Correct |
46 ms |
11888 KB |
Output is correct |
13 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2656 KB |
Output is correct |
4 |
Correct |
2 ms |
2776 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2692 KB |
Output is correct |
11 |
Correct |
2 ms |
2656 KB |
Output is correct |
12 |
Correct |
2 ms |
2660 KB |
Output is correct |
13 |
Correct |
2 ms |
2656 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2656 KB |
Output is correct |
20 |
Correct |
2 ms |
2656 KB |
Output is correct |
21 |
Correct |
2 ms |
2660 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2656 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
13388 KB |
Output is correct |
2 |
Correct |
47 ms |
13100 KB |
Output is correct |
3 |
Correct |
29 ms |
11292 KB |
Output is correct |
4 |
Correct |
7 ms |
4224 KB |
Output is correct |
5 |
Correct |
6 ms |
3532 KB |
Output is correct |
6 |
Correct |
11 ms |
5076 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
22 ms |
7128 KB |
Output is correct |
9 |
Correct |
34 ms |
9396 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
40 ms |
10624 KB |
Output is correct |
12 |
Correct |
46 ms |
11888 KB |
Output is correct |
13 |
Correct |
2 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2656 KB |
Output is correct |
17 |
Correct |
2 ms |
2776 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2692 KB |
Output is correct |
24 |
Correct |
2 ms |
2656 KB |
Output is correct |
25 |
Correct |
2 ms |
2660 KB |
Output is correct |
26 |
Correct |
2 ms |
2656 KB |
Output is correct |
27 |
Correct |
2 ms |
2644 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2644 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2644 KB |
Output is correct |
32 |
Correct |
2 ms |
2656 KB |
Output is correct |
33 |
Correct |
2 ms |
2656 KB |
Output is correct |
34 |
Correct |
2 ms |
2660 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
2 ms |
2656 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
47 ms |
13388 KB |
Output is correct |
40 |
Correct |
45 ms |
13064 KB |
Output is correct |
41 |
Correct |
28 ms |
11336 KB |
Output is correct |
42 |
Correct |
8 ms |
4180 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
2 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2656 KB |
Output is correct |
46 |
Correct |
2 ms |
2644 KB |
Output is correct |
47 |
Correct |
2 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2644 KB |
Output is correct |
49 |
Correct |
1 ms |
2656 KB |
Output is correct |
50 |
Correct |
2 ms |
2656 KB |
Output is correct |
51 |
Correct |
2 ms |
2644 KB |
Output is correct |
52 |
Correct |
2 ms |
2644 KB |
Output is correct |
53 |
Correct |
2 ms |
2644 KB |
Output is correct |
54 |
Correct |
1 ms |
2644 KB |
Output is correct |
55 |
Correct |
2 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2644 KB |
Output is correct |
57 |
Correct |
57 ms |
10900 KB |
Output is correct |
58 |
Correct |
66 ms |
10752 KB |
Output is correct |
59 |
Correct |
61 ms |
10792 KB |
Output is correct |
60 |
Correct |
57 ms |
10716 KB |
Output is correct |
61 |
Correct |
58 ms |
10824 KB |
Output is correct |
62 |
Correct |
54 ms |
10764 KB |
Output is correct |
63 |
Correct |
53 ms |
10636 KB |
Output is correct |
64 |
Correct |
58 ms |
10572 KB |
Output is correct |
65 |
Correct |
57 ms |
10884 KB |
Output is correct |
66 |
Correct |
56 ms |
10824 KB |
Output is correct |
67 |
Correct |
56 ms |
10776 KB |
Output is correct |
68 |
Correct |
59 ms |
10784 KB |
Output is correct |
69 |
Correct |
59 ms |
10980 KB |
Output is correct |
70 |
Correct |
59 ms |
10952 KB |
Output is correct |
71 |
Correct |
2 ms |
2648 KB |
Output is correct |
72 |
Correct |
3 ms |
2900 KB |
Output is correct |
73 |
Correct |
4 ms |
2900 KB |
Output is correct |
74 |
Correct |
3 ms |
2900 KB |
Output is correct |
75 |
Correct |
3 ms |
2900 KB |
Output is correct |
76 |
Correct |
3 ms |
2900 KB |
Output is correct |
77 |
Correct |
3 ms |
2948 KB |
Output is correct |
78 |
Correct |
3 ms |
2900 KB |
Output is correct |
79 |
Correct |
3 ms |
3028 KB |
Output is correct |
80 |
Correct |
59 ms |
11068 KB |
Output is correct |
81 |
Correct |
59 ms |
10708 KB |
Output is correct |
82 |
Correct |
54 ms |
10952 KB |
Output is correct |
83 |
Correct |
63 ms |
10964 KB |
Output is correct |
84 |
Correct |
3 ms |
2816 KB |
Output is correct |
85 |
Correct |
3 ms |
2772 KB |
Output is correct |
86 |
Correct |
3 ms |
2772 KB |
Output is correct |
87 |
Correct |
3 ms |
2772 KB |
Output is correct |
88 |
Correct |
3 ms |
2772 KB |
Output is correct |
89 |
Correct |
3 ms |
2828 KB |
Output is correct |
90 |
Correct |
3 ms |
2772 KB |
Output is correct |
91 |
Correct |
3 ms |
2900 KB |
Output is correct |
92 |
Correct |
3 ms |
2900 KB |
Output is correct |
93 |
Correct |
2 ms |
2796 KB |
Output is correct |
94 |
Correct |
2 ms |
2644 KB |
Output is correct |
95 |
Correct |
2 ms |
2644 KB |
Output is correct |
96 |
Correct |
2 ms |
2768 KB |
Output is correct |
97 |
Correct |
2 ms |
2656 KB |
Output is correct |
98 |
Correct |
2 ms |
2644 KB |
Output is correct |
99 |
Correct |
2 ms |
2644 KB |
Output is correct |
100 |
Correct |
2 ms |
2644 KB |
Output is correct |
101 |
Correct |
3 ms |
2644 KB |
Output is correct |
102 |
Correct |
2 ms |
2644 KB |
Output is correct |
103 |
Correct |
2 ms |
2656 KB |
Output is correct |
104 |
Correct |
6 ms |
3540 KB |
Output is correct |
105 |
Correct |
11 ms |
5104 KB |
Output is correct |
106 |
Correct |
2 ms |
2644 KB |
Output is correct |
107 |
Correct |
20 ms |
7104 KB |
Output is correct |
108 |
Correct |
28 ms |
9428 KB |
Output is correct |
109 |
Correct |
2 ms |
2772 KB |
Output is correct |
110 |
Correct |
45 ms |
10572 KB |
Output is correct |
111 |
Correct |
54 ms |
11844 KB |
Output is correct |
112 |
Correct |
2 ms |
2772 KB |
Output is correct |
113 |
Correct |
72 ms |
18020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
6740 KB |
Output is correct |
2 |
Incorrect |
18 ms |
6868 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2656 KB |
Output is correct |
4 |
Correct |
2 ms |
2776 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2692 KB |
Output is correct |
11 |
Correct |
2 ms |
2656 KB |
Output is correct |
12 |
Correct |
2 ms |
2660 KB |
Output is correct |
13 |
Correct |
2 ms |
2656 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2656 KB |
Output is correct |
20 |
Correct |
2 ms |
2656 KB |
Output is correct |
21 |
Correct |
2 ms |
2660 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2656 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
3 ms |
2644 KB |
Output is correct |
27 |
Correct |
2 ms |
2796 KB |
Output is correct |
28 |
Correct |
3 ms |
2796 KB |
Output is correct |
29 |
Correct |
2 ms |
2644 KB |
Output is correct |
30 |
Correct |
3 ms |
2772 KB |
Output is correct |
31 |
Correct |
3 ms |
2900 KB |
Output is correct |
32 |
Incorrect |
3 ms |
2644 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
13388 KB |
Output is correct |
2 |
Correct |
47 ms |
13100 KB |
Output is correct |
3 |
Correct |
29 ms |
11292 KB |
Output is correct |
4 |
Correct |
7 ms |
4224 KB |
Output is correct |
5 |
Correct |
6 ms |
3532 KB |
Output is correct |
6 |
Correct |
11 ms |
5076 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
22 ms |
7128 KB |
Output is correct |
9 |
Correct |
34 ms |
9396 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
40 ms |
10624 KB |
Output is correct |
12 |
Correct |
46 ms |
11888 KB |
Output is correct |
13 |
Correct |
2 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2656 KB |
Output is correct |
17 |
Correct |
2 ms |
2776 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2692 KB |
Output is correct |
24 |
Correct |
2 ms |
2656 KB |
Output is correct |
25 |
Correct |
2 ms |
2660 KB |
Output is correct |
26 |
Correct |
2 ms |
2656 KB |
Output is correct |
27 |
Correct |
2 ms |
2644 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2644 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2644 KB |
Output is correct |
32 |
Correct |
2 ms |
2656 KB |
Output is correct |
33 |
Correct |
2 ms |
2656 KB |
Output is correct |
34 |
Correct |
2 ms |
2660 KB |
Output is correct |
35 |
Correct |
2 ms |
2652 KB |
Output is correct |
36 |
Correct |
2 ms |
2656 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
47 ms |
13388 KB |
Output is correct |
40 |
Correct |
45 ms |
13064 KB |
Output is correct |
41 |
Correct |
28 ms |
11336 KB |
Output is correct |
42 |
Correct |
8 ms |
4180 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
2 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2656 KB |
Output is correct |
46 |
Correct |
2 ms |
2644 KB |
Output is correct |
47 |
Correct |
2 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2644 KB |
Output is correct |
49 |
Correct |
1 ms |
2656 KB |
Output is correct |
50 |
Correct |
2 ms |
2656 KB |
Output is correct |
51 |
Correct |
2 ms |
2644 KB |
Output is correct |
52 |
Correct |
2 ms |
2644 KB |
Output is correct |
53 |
Correct |
2 ms |
2644 KB |
Output is correct |
54 |
Correct |
1 ms |
2644 KB |
Output is correct |
55 |
Correct |
2 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2644 KB |
Output is correct |
57 |
Correct |
57 ms |
10900 KB |
Output is correct |
58 |
Correct |
66 ms |
10752 KB |
Output is correct |
59 |
Correct |
61 ms |
10792 KB |
Output is correct |
60 |
Correct |
57 ms |
10716 KB |
Output is correct |
61 |
Correct |
58 ms |
10824 KB |
Output is correct |
62 |
Correct |
54 ms |
10764 KB |
Output is correct |
63 |
Correct |
53 ms |
10636 KB |
Output is correct |
64 |
Correct |
58 ms |
10572 KB |
Output is correct |
65 |
Correct |
57 ms |
10884 KB |
Output is correct |
66 |
Correct |
56 ms |
10824 KB |
Output is correct |
67 |
Correct |
56 ms |
10776 KB |
Output is correct |
68 |
Correct |
59 ms |
10784 KB |
Output is correct |
69 |
Correct |
59 ms |
10980 KB |
Output is correct |
70 |
Correct |
59 ms |
10952 KB |
Output is correct |
71 |
Correct |
2 ms |
2648 KB |
Output is correct |
72 |
Correct |
3 ms |
2900 KB |
Output is correct |
73 |
Correct |
4 ms |
2900 KB |
Output is correct |
74 |
Correct |
3 ms |
2900 KB |
Output is correct |
75 |
Correct |
3 ms |
2900 KB |
Output is correct |
76 |
Correct |
3 ms |
2900 KB |
Output is correct |
77 |
Correct |
3 ms |
2948 KB |
Output is correct |
78 |
Correct |
3 ms |
2900 KB |
Output is correct |
79 |
Correct |
3 ms |
3028 KB |
Output is correct |
80 |
Correct |
59 ms |
11068 KB |
Output is correct |
81 |
Correct |
59 ms |
10708 KB |
Output is correct |
82 |
Correct |
54 ms |
10952 KB |
Output is correct |
83 |
Correct |
63 ms |
10964 KB |
Output is correct |
84 |
Correct |
3 ms |
2816 KB |
Output is correct |
85 |
Correct |
3 ms |
2772 KB |
Output is correct |
86 |
Correct |
3 ms |
2772 KB |
Output is correct |
87 |
Correct |
3 ms |
2772 KB |
Output is correct |
88 |
Correct |
3 ms |
2772 KB |
Output is correct |
89 |
Correct |
3 ms |
2828 KB |
Output is correct |
90 |
Correct |
3 ms |
2772 KB |
Output is correct |
91 |
Correct |
3 ms |
2900 KB |
Output is correct |
92 |
Correct |
3 ms |
2900 KB |
Output is correct |
93 |
Correct |
2 ms |
2796 KB |
Output is correct |
94 |
Correct |
2 ms |
2644 KB |
Output is correct |
95 |
Correct |
2 ms |
2644 KB |
Output is correct |
96 |
Correct |
2 ms |
2768 KB |
Output is correct |
97 |
Correct |
2 ms |
2656 KB |
Output is correct |
98 |
Correct |
2 ms |
2644 KB |
Output is correct |
99 |
Correct |
2 ms |
2644 KB |
Output is correct |
100 |
Correct |
2 ms |
2644 KB |
Output is correct |
101 |
Correct |
3 ms |
2644 KB |
Output is correct |
102 |
Correct |
2 ms |
2644 KB |
Output is correct |
103 |
Correct |
2 ms |
2656 KB |
Output is correct |
104 |
Correct |
6 ms |
3540 KB |
Output is correct |
105 |
Correct |
11 ms |
5104 KB |
Output is correct |
106 |
Correct |
2 ms |
2644 KB |
Output is correct |
107 |
Correct |
20 ms |
7104 KB |
Output is correct |
108 |
Correct |
28 ms |
9428 KB |
Output is correct |
109 |
Correct |
2 ms |
2772 KB |
Output is correct |
110 |
Correct |
45 ms |
10572 KB |
Output is correct |
111 |
Correct |
54 ms |
11844 KB |
Output is correct |
112 |
Correct |
2 ms |
2772 KB |
Output is correct |
113 |
Correct |
72 ms |
18020 KB |
Output is correct |
114 |
Correct |
18 ms |
6740 KB |
Output is correct |
115 |
Incorrect |
18 ms |
6868 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |