#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
int n, m, l;
const int N =100005;
bool vis[N];
multiset<int> ms[N];
vector<array<int, 2>> adj[N];
vector<array<int, 2>> comp;
int dfs1(int node, int par)
{
vis[node] = true;
int res = 0;
ms[node].insert(0);
for (auto next : adj[node])
{
if (next[0] == par) continue;
int cur = dfs1(next[0], node) + next[1];
res = max(res, cur);
ms[node].insert(cur);
}
return res;
}
int dfs2(int node, int par, int pdist)
{
if (par != -1)
{
int del = *ms[node].rbegin() + pdist;
ms[par].erase(ms[par].find(del));
ms[node].insert(*ms[par].rbegin() + pdist);
ms[par].insert(del);
}
int res = *ms[node].rbegin();
for (auto next : adj[node])
{
if (next[0] == par) continue;
res = min(res, dfs2(next[0], node, next[1]));
}
return res;
}
array<int, 2> dfs3(int node, int par)
{
array<int, 2> best = {node, 0};
for (auto next : adj[node])
{
if (next[0] == par) continue;
auto cur = dfs3(next[0],node);
cur[1] += next[1];
if (cur[1] > best[1])
{
best = cur;
}
}
return best;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
n = N;
m = M;
l = L;
for (int i = 0; i < m; i++)
{
adj[A[i]].push_back({B[i], T[i]});
adj[B[i]].push_back({A[i], T[i]});
}
for (int i = 0; i < n; i++)
{
if (!vis[i])
{
dfs1(i, -1);
int cent = dfs2(i, -1, -1);
auto cur = dfs3(i, -1);
int mdist = dfs3(cur[0], -1)[1];
comp.push_back({cent, mdist});
}
}
return max({comp[0][0] + comp[1][0] + l, comp[0][1], comp[1][1]});
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
32736 KB |
Output is correct |
2 |
Correct |
156 ms |
32748 KB |
Output is correct |
3 |
Correct |
94 ms |
24172 KB |
Output is correct |
4 |
Correct |
19 ms |
11116 KB |
Output is correct |
5 |
Correct |
16 ms |
9708 KB |
Output is correct |
6 |
Correct |
32 ms |
13292 KB |
Output is correct |
7 |
Correct |
7 ms |
7404 KB |
Output is correct |
8 |
Correct |
71 ms |
17516 KB |
Output is correct |
9 |
Correct |
89 ms |
21612 KB |
Output is correct |
10 |
Correct |
6 ms |
7532 KB |
Output is correct |
11 |
Correct |
142 ms |
25964 KB |
Output is correct |
12 |
Correct |
184 ms |
29804 KB |
Output is correct |
13 |
Correct |
6 ms |
7660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
5 ms |
7404 KB |
Output is correct |
5 |
Correct |
5 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
6 ms |
7404 KB |
Output is correct |
8 |
Correct |
5 ms |
7404 KB |
Output is correct |
9 |
Correct |
5 ms |
7404 KB |
Output is correct |
10 |
Correct |
5 ms |
7404 KB |
Output is correct |
11 |
Correct |
5 ms |
7404 KB |
Output is correct |
12 |
Correct |
5 ms |
7404 KB |
Output is correct |
13 |
Correct |
5 ms |
7404 KB |
Output is correct |
14 |
Correct |
5 ms |
7404 KB |
Output is correct |
15 |
Correct |
5 ms |
7404 KB |
Output is correct |
16 |
Correct |
5 ms |
7404 KB |
Output is correct |
17 |
Correct |
5 ms |
7404 KB |
Output is correct |
18 |
Correct |
6 ms |
7404 KB |
Output is correct |
19 |
Correct |
5 ms |
7404 KB |
Output is correct |
20 |
Correct |
5 ms |
7404 KB |
Output is correct |
21 |
Correct |
5 ms |
7404 KB |
Output is correct |
22 |
Correct |
5 ms |
7404 KB |
Output is correct |
23 |
Correct |
6 ms |
7404 KB |
Output is correct |
24 |
Correct |
5 ms |
7404 KB |
Output is correct |
25 |
Correct |
5 ms |
7404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
32736 KB |
Output is correct |
2 |
Correct |
156 ms |
32748 KB |
Output is correct |
3 |
Correct |
94 ms |
24172 KB |
Output is correct |
4 |
Correct |
19 ms |
11116 KB |
Output is correct |
5 |
Correct |
16 ms |
9708 KB |
Output is correct |
6 |
Correct |
32 ms |
13292 KB |
Output is correct |
7 |
Correct |
7 ms |
7404 KB |
Output is correct |
8 |
Correct |
71 ms |
17516 KB |
Output is correct |
9 |
Correct |
89 ms |
21612 KB |
Output is correct |
10 |
Correct |
6 ms |
7532 KB |
Output is correct |
11 |
Correct |
142 ms |
25964 KB |
Output is correct |
12 |
Correct |
184 ms |
29804 KB |
Output is correct |
13 |
Correct |
6 ms |
7660 KB |
Output is correct |
14 |
Correct |
5 ms |
7404 KB |
Output is correct |
15 |
Correct |
5 ms |
7404 KB |
Output is correct |
16 |
Correct |
5 ms |
7404 KB |
Output is correct |
17 |
Correct |
5 ms |
7404 KB |
Output is correct |
18 |
Correct |
5 ms |
7404 KB |
Output is correct |
19 |
Correct |
6 ms |
7404 KB |
Output is correct |
20 |
Correct |
6 ms |
7404 KB |
Output is correct |
21 |
Correct |
5 ms |
7404 KB |
Output is correct |
22 |
Correct |
5 ms |
7404 KB |
Output is correct |
23 |
Correct |
5 ms |
7404 KB |
Output is correct |
24 |
Correct |
5 ms |
7404 KB |
Output is correct |
25 |
Correct |
5 ms |
7404 KB |
Output is correct |
26 |
Correct |
5 ms |
7404 KB |
Output is correct |
27 |
Correct |
5 ms |
7404 KB |
Output is correct |
28 |
Correct |
5 ms |
7404 KB |
Output is correct |
29 |
Correct |
5 ms |
7404 KB |
Output is correct |
30 |
Correct |
5 ms |
7404 KB |
Output is correct |
31 |
Correct |
6 ms |
7404 KB |
Output is correct |
32 |
Correct |
5 ms |
7404 KB |
Output is correct |
33 |
Correct |
5 ms |
7404 KB |
Output is correct |
34 |
Correct |
5 ms |
7404 KB |
Output is correct |
35 |
Correct |
5 ms |
7404 KB |
Output is correct |
36 |
Correct |
6 ms |
7404 KB |
Output is correct |
37 |
Correct |
5 ms |
7404 KB |
Output is correct |
38 |
Correct |
5 ms |
7404 KB |
Output is correct |
39 |
Correct |
163 ms |
34028 KB |
Output is correct |
40 |
Correct |
165 ms |
34028 KB |
Output is correct |
41 |
Correct |
94 ms |
24960 KB |
Output is correct |
42 |
Correct |
19 ms |
11244 KB |
Output is correct |
43 |
Correct |
5 ms |
7404 KB |
Output is correct |
44 |
Correct |
5 ms |
7404 KB |
Output is correct |
45 |
Correct |
6 ms |
7404 KB |
Output is correct |
46 |
Correct |
5 ms |
7404 KB |
Output is correct |
47 |
Correct |
5 ms |
7404 KB |
Output is correct |
48 |
Correct |
6 ms |
7404 KB |
Output is correct |
49 |
Correct |
5 ms |
7404 KB |
Output is correct |
50 |
Correct |
6 ms |
7404 KB |
Output is correct |
51 |
Correct |
5 ms |
7404 KB |
Output is correct |
52 |
Correct |
5 ms |
7404 KB |
Output is correct |
53 |
Correct |
6 ms |
7404 KB |
Output is correct |
54 |
Correct |
6 ms |
7404 KB |
Output is correct |
55 |
Correct |
5 ms |
7404 KB |
Output is correct |
56 |
Correct |
6 ms |
7404 KB |
Output is correct |
57 |
Correct |
202 ms |
28012 KB |
Output is correct |
58 |
Correct |
202 ms |
28012 KB |
Output is correct |
59 |
Correct |
193 ms |
28140 KB |
Output is correct |
60 |
Correct |
205 ms |
28012 KB |
Output is correct |
61 |
Correct |
212 ms |
28140 KB |
Output is correct |
62 |
Correct |
193 ms |
28268 KB |
Output is correct |
63 |
Correct |
183 ms |
27756 KB |
Output is correct |
64 |
Correct |
186 ms |
27884 KB |
Output is correct |
65 |
Correct |
229 ms |
28084 KB |
Output is correct |
66 |
Correct |
186 ms |
28012 KB |
Output is correct |
67 |
Correct |
201 ms |
28012 KB |
Output is correct |
68 |
Correct |
189 ms |
28012 KB |
Output is correct |
69 |
Correct |
213 ms |
28396 KB |
Output is correct |
70 |
Correct |
202 ms |
28268 KB |
Output is correct |
71 |
Correct |
5 ms |
7404 KB |
Output is correct |
72 |
Correct |
9 ms |
8044 KB |
Output is correct |
73 |
Correct |
9 ms |
8044 KB |
Output is correct |
74 |
Correct |
8 ms |
8044 KB |
Output is correct |
75 |
Correct |
9 ms |
8044 KB |
Output is correct |
76 |
Correct |
8 ms |
8044 KB |
Output is correct |
77 |
Correct |
8 ms |
8044 KB |
Output is correct |
78 |
Correct |
8 ms |
8044 KB |
Output is correct |
79 |
Correct |
9 ms |
8044 KB |
Output is correct |
80 |
Correct |
192 ms |
28012 KB |
Output is correct |
81 |
Correct |
208 ms |
28012 KB |
Output is correct |
82 |
Correct |
196 ms |
28140 KB |
Output is correct |
83 |
Correct |
193 ms |
28184 KB |
Output is correct |
84 |
Correct |
8 ms |
7916 KB |
Output is correct |
85 |
Correct |
7 ms |
7788 KB |
Output is correct |
86 |
Correct |
8 ms |
7916 KB |
Output is correct |
87 |
Correct |
8 ms |
7916 KB |
Output is correct |
88 |
Correct |
8 ms |
7860 KB |
Output is correct |
89 |
Correct |
9 ms |
7916 KB |
Output is correct |
90 |
Correct |
10 ms |
7916 KB |
Output is correct |
91 |
Correct |
9 ms |
8044 KB |
Output is correct |
92 |
Correct |
8 ms |
7916 KB |
Output is correct |
93 |
Correct |
8 ms |
7916 KB |
Output is correct |
94 |
Correct |
5 ms |
7404 KB |
Output is correct |
95 |
Correct |
5 ms |
7404 KB |
Output is correct |
96 |
Correct |
6 ms |
7404 KB |
Output is correct |
97 |
Correct |
5 ms |
7404 KB |
Output is correct |
98 |
Correct |
5 ms |
7404 KB |
Output is correct |
99 |
Correct |
5 ms |
7404 KB |
Output is correct |
100 |
Correct |
7 ms |
7532 KB |
Output is correct |
101 |
Correct |
7 ms |
7404 KB |
Output is correct |
102 |
Correct |
5 ms |
7404 KB |
Output is correct |
103 |
Correct |
5 ms |
7404 KB |
Output is correct |
104 |
Correct |
16 ms |
9836 KB |
Output is correct |
105 |
Correct |
33 ms |
13440 KB |
Output is correct |
106 |
Correct |
6 ms |
7552 KB |
Output is correct |
107 |
Correct |
67 ms |
17516 KB |
Output is correct |
108 |
Correct |
92 ms |
21612 KB |
Output is correct |
109 |
Correct |
6 ms |
7532 KB |
Output is correct |
110 |
Correct |
145 ms |
25964 KB |
Output is correct |
111 |
Correct |
165 ms |
29804 KB |
Output is correct |
112 |
Correct |
7 ms |
7808 KB |
Output is correct |
113 |
Correct |
234 ms |
38252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
17640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
5 ms |
7404 KB |
Output is correct |
5 |
Correct |
5 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
6 ms |
7404 KB |
Output is correct |
8 |
Correct |
5 ms |
7404 KB |
Output is correct |
9 |
Correct |
5 ms |
7404 KB |
Output is correct |
10 |
Correct |
5 ms |
7404 KB |
Output is correct |
11 |
Correct |
5 ms |
7404 KB |
Output is correct |
12 |
Correct |
5 ms |
7404 KB |
Output is correct |
13 |
Correct |
5 ms |
7404 KB |
Output is correct |
14 |
Correct |
5 ms |
7404 KB |
Output is correct |
15 |
Correct |
5 ms |
7404 KB |
Output is correct |
16 |
Correct |
5 ms |
7404 KB |
Output is correct |
17 |
Correct |
5 ms |
7404 KB |
Output is correct |
18 |
Correct |
6 ms |
7404 KB |
Output is correct |
19 |
Correct |
5 ms |
7404 KB |
Output is correct |
20 |
Correct |
5 ms |
7404 KB |
Output is correct |
21 |
Correct |
5 ms |
7404 KB |
Output is correct |
22 |
Correct |
5 ms |
7404 KB |
Output is correct |
23 |
Correct |
6 ms |
7404 KB |
Output is correct |
24 |
Correct |
5 ms |
7404 KB |
Output is correct |
25 |
Correct |
5 ms |
7404 KB |
Output is correct |
26 |
Incorrect |
6 ms |
7532 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
32736 KB |
Output is correct |
2 |
Correct |
156 ms |
32748 KB |
Output is correct |
3 |
Correct |
94 ms |
24172 KB |
Output is correct |
4 |
Correct |
19 ms |
11116 KB |
Output is correct |
5 |
Correct |
16 ms |
9708 KB |
Output is correct |
6 |
Correct |
32 ms |
13292 KB |
Output is correct |
7 |
Correct |
7 ms |
7404 KB |
Output is correct |
8 |
Correct |
71 ms |
17516 KB |
Output is correct |
9 |
Correct |
89 ms |
21612 KB |
Output is correct |
10 |
Correct |
6 ms |
7532 KB |
Output is correct |
11 |
Correct |
142 ms |
25964 KB |
Output is correct |
12 |
Correct |
184 ms |
29804 KB |
Output is correct |
13 |
Correct |
6 ms |
7660 KB |
Output is correct |
14 |
Correct |
5 ms |
7404 KB |
Output is correct |
15 |
Correct |
5 ms |
7404 KB |
Output is correct |
16 |
Correct |
5 ms |
7404 KB |
Output is correct |
17 |
Correct |
5 ms |
7404 KB |
Output is correct |
18 |
Correct |
5 ms |
7404 KB |
Output is correct |
19 |
Correct |
6 ms |
7404 KB |
Output is correct |
20 |
Correct |
6 ms |
7404 KB |
Output is correct |
21 |
Correct |
5 ms |
7404 KB |
Output is correct |
22 |
Correct |
5 ms |
7404 KB |
Output is correct |
23 |
Correct |
5 ms |
7404 KB |
Output is correct |
24 |
Correct |
5 ms |
7404 KB |
Output is correct |
25 |
Correct |
5 ms |
7404 KB |
Output is correct |
26 |
Correct |
5 ms |
7404 KB |
Output is correct |
27 |
Correct |
5 ms |
7404 KB |
Output is correct |
28 |
Correct |
5 ms |
7404 KB |
Output is correct |
29 |
Correct |
5 ms |
7404 KB |
Output is correct |
30 |
Correct |
5 ms |
7404 KB |
Output is correct |
31 |
Correct |
6 ms |
7404 KB |
Output is correct |
32 |
Correct |
5 ms |
7404 KB |
Output is correct |
33 |
Correct |
5 ms |
7404 KB |
Output is correct |
34 |
Correct |
5 ms |
7404 KB |
Output is correct |
35 |
Correct |
5 ms |
7404 KB |
Output is correct |
36 |
Correct |
6 ms |
7404 KB |
Output is correct |
37 |
Correct |
5 ms |
7404 KB |
Output is correct |
38 |
Correct |
5 ms |
7404 KB |
Output is correct |
39 |
Correct |
163 ms |
34028 KB |
Output is correct |
40 |
Correct |
165 ms |
34028 KB |
Output is correct |
41 |
Correct |
94 ms |
24960 KB |
Output is correct |
42 |
Correct |
19 ms |
11244 KB |
Output is correct |
43 |
Correct |
5 ms |
7404 KB |
Output is correct |
44 |
Correct |
5 ms |
7404 KB |
Output is correct |
45 |
Correct |
6 ms |
7404 KB |
Output is correct |
46 |
Correct |
5 ms |
7404 KB |
Output is correct |
47 |
Correct |
5 ms |
7404 KB |
Output is correct |
48 |
Correct |
6 ms |
7404 KB |
Output is correct |
49 |
Correct |
5 ms |
7404 KB |
Output is correct |
50 |
Correct |
6 ms |
7404 KB |
Output is correct |
51 |
Correct |
5 ms |
7404 KB |
Output is correct |
52 |
Correct |
5 ms |
7404 KB |
Output is correct |
53 |
Correct |
6 ms |
7404 KB |
Output is correct |
54 |
Correct |
6 ms |
7404 KB |
Output is correct |
55 |
Correct |
5 ms |
7404 KB |
Output is correct |
56 |
Correct |
6 ms |
7404 KB |
Output is correct |
57 |
Correct |
202 ms |
28012 KB |
Output is correct |
58 |
Correct |
202 ms |
28012 KB |
Output is correct |
59 |
Correct |
193 ms |
28140 KB |
Output is correct |
60 |
Correct |
205 ms |
28012 KB |
Output is correct |
61 |
Correct |
212 ms |
28140 KB |
Output is correct |
62 |
Correct |
193 ms |
28268 KB |
Output is correct |
63 |
Correct |
183 ms |
27756 KB |
Output is correct |
64 |
Correct |
186 ms |
27884 KB |
Output is correct |
65 |
Correct |
229 ms |
28084 KB |
Output is correct |
66 |
Correct |
186 ms |
28012 KB |
Output is correct |
67 |
Correct |
201 ms |
28012 KB |
Output is correct |
68 |
Correct |
189 ms |
28012 KB |
Output is correct |
69 |
Correct |
213 ms |
28396 KB |
Output is correct |
70 |
Correct |
202 ms |
28268 KB |
Output is correct |
71 |
Correct |
5 ms |
7404 KB |
Output is correct |
72 |
Correct |
9 ms |
8044 KB |
Output is correct |
73 |
Correct |
9 ms |
8044 KB |
Output is correct |
74 |
Correct |
8 ms |
8044 KB |
Output is correct |
75 |
Correct |
9 ms |
8044 KB |
Output is correct |
76 |
Correct |
8 ms |
8044 KB |
Output is correct |
77 |
Correct |
8 ms |
8044 KB |
Output is correct |
78 |
Correct |
8 ms |
8044 KB |
Output is correct |
79 |
Correct |
9 ms |
8044 KB |
Output is correct |
80 |
Correct |
192 ms |
28012 KB |
Output is correct |
81 |
Correct |
208 ms |
28012 KB |
Output is correct |
82 |
Correct |
196 ms |
28140 KB |
Output is correct |
83 |
Correct |
193 ms |
28184 KB |
Output is correct |
84 |
Correct |
8 ms |
7916 KB |
Output is correct |
85 |
Correct |
7 ms |
7788 KB |
Output is correct |
86 |
Correct |
8 ms |
7916 KB |
Output is correct |
87 |
Correct |
8 ms |
7916 KB |
Output is correct |
88 |
Correct |
8 ms |
7860 KB |
Output is correct |
89 |
Correct |
9 ms |
7916 KB |
Output is correct |
90 |
Correct |
10 ms |
7916 KB |
Output is correct |
91 |
Correct |
9 ms |
8044 KB |
Output is correct |
92 |
Correct |
8 ms |
7916 KB |
Output is correct |
93 |
Correct |
8 ms |
7916 KB |
Output is correct |
94 |
Correct |
5 ms |
7404 KB |
Output is correct |
95 |
Correct |
5 ms |
7404 KB |
Output is correct |
96 |
Correct |
6 ms |
7404 KB |
Output is correct |
97 |
Correct |
5 ms |
7404 KB |
Output is correct |
98 |
Correct |
5 ms |
7404 KB |
Output is correct |
99 |
Correct |
5 ms |
7404 KB |
Output is correct |
100 |
Correct |
7 ms |
7532 KB |
Output is correct |
101 |
Correct |
7 ms |
7404 KB |
Output is correct |
102 |
Correct |
5 ms |
7404 KB |
Output is correct |
103 |
Correct |
5 ms |
7404 KB |
Output is correct |
104 |
Correct |
16 ms |
9836 KB |
Output is correct |
105 |
Correct |
33 ms |
13440 KB |
Output is correct |
106 |
Correct |
6 ms |
7552 KB |
Output is correct |
107 |
Correct |
67 ms |
17516 KB |
Output is correct |
108 |
Correct |
92 ms |
21612 KB |
Output is correct |
109 |
Correct |
6 ms |
7532 KB |
Output is correct |
110 |
Correct |
145 ms |
25964 KB |
Output is correct |
111 |
Correct |
165 ms |
29804 KB |
Output is correct |
112 |
Correct |
7 ms |
7808 KB |
Output is correct |
113 |
Correct |
234 ms |
38252 KB |
Output is correct |
114 |
Incorrect |
51 ms |
17640 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |