#include "dreaming.h"
#include <bits/stdc++.h>
#define sc second
#define fr first
#define mk make_pair
#define pb push_back
using namespace std;
const int NN = (1e6 + 5);
const int inf = (1e9 + 7);
int n,m,l;
int par[NN],dis[NN],u[NN];
int mx = -1;
int mxx;
int cur;
vector <pair<int,int> > g[NN];
vector <int> ans;
void dfs (int v,int d = 0,int p = -1) {
u[v] = 1;
par[v] = p;
dis[v] = d;
if (mx < d) mx = d,cur = v;
for (auto to : g[v]) {
if (to.fr != p) dfs(to.fr,d + to.sc,v);
}
}
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 ++) {
A[i] ++;
B[i] ++;
g[A[i]].pb(mk(B[i],T[i]));
g[B[i]].pb(mk(A[i],T[i]));
}
for (int i = 1; i <= n; i ++) {
if (!u[i]) {
cur = 0,mx = -1;
dfs(i);
mxx = max(mxx,mx);
int c = cur,res = inf;
cur = 0,mx = -1;
dfs(c);
c = cur;
mxx = max(mxx,mx);
while (c != -1) {
res = min(res,max(dis[c],dis[cur] - dis[c]));
c = par[c];
}
ans.pb(res);
}
}
sort(ans.rbegin(),ans.rend());
if (ans.size() > 1) return max(mxx,ans[0] + ans[1] + l);
return mxx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
34364 KB |
Output is correct |
2 |
Correct |
92 ms |
34424 KB |
Output is correct |
3 |
Correct |
67 ms |
30968 KB |
Output is correct |
4 |
Correct |
33 ms |
25336 KB |
Output is correct |
5 |
Correct |
30 ms |
24696 KB |
Output is correct |
6 |
Correct |
39 ms |
26232 KB |
Output is correct |
7 |
Correct |
23 ms |
23928 KB |
Output is correct |
8 |
Correct |
54 ms |
27640 KB |
Output is correct |
9 |
Correct |
63 ms |
29176 KB |
Output is correct |
10 |
Correct |
23 ms |
23928 KB |
Output is correct |
11 |
Correct |
81 ms |
31224 KB |
Output is correct |
12 |
Correct |
85 ms |
32632 KB |
Output is correct |
13 |
Correct |
23 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
34364 KB |
Output is correct |
2 |
Correct |
92 ms |
34424 KB |
Output is correct |
3 |
Correct |
67 ms |
30968 KB |
Output is correct |
4 |
Correct |
33 ms |
25336 KB |
Output is correct |
5 |
Correct |
30 ms |
24696 KB |
Output is correct |
6 |
Correct |
39 ms |
26232 KB |
Output is correct |
7 |
Correct |
23 ms |
23928 KB |
Output is correct |
8 |
Correct |
54 ms |
27640 KB |
Output is correct |
9 |
Correct |
63 ms |
29176 KB |
Output is correct |
10 |
Correct |
23 ms |
23928 KB |
Output is correct |
11 |
Correct |
81 ms |
31224 KB |
Output is correct |
12 |
Correct |
85 ms |
32632 KB |
Output is correct |
13 |
Correct |
23 ms |
23928 KB |
Output is correct |
14 |
Correct |
23 ms |
23800 KB |
Output is correct |
15 |
Correct |
23 ms |
23800 KB |
Output is correct |
16 |
Correct |
23 ms |
23928 KB |
Output is correct |
17 |
Correct |
23 ms |
23928 KB |
Output is correct |
18 |
Correct |
23 ms |
23928 KB |
Output is correct |
19 |
Correct |
23 ms |
23800 KB |
Output is correct |
20 |
Correct |
24 ms |
23800 KB |
Output is correct |
21 |
Correct |
24 ms |
23800 KB |
Output is correct |
22 |
Correct |
23 ms |
23800 KB |
Output is correct |
23 |
Correct |
23 ms |
23928 KB |
Output is correct |
24 |
Correct |
23 ms |
23800 KB |
Output is correct |
25 |
Correct |
23 ms |
23800 KB |
Output is correct |
26 |
Correct |
23 ms |
23800 KB |
Output is correct |
27 |
Correct |
28 ms |
23928 KB |
Output is correct |
28 |
Correct |
23 ms |
23800 KB |
Output is correct |
29 |
Correct |
23 ms |
23928 KB |
Output is correct |
30 |
Correct |
27 ms |
23868 KB |
Output is correct |
31 |
Correct |
23 ms |
23800 KB |
Output is correct |
32 |
Correct |
23 ms |
23928 KB |
Output is correct |
33 |
Correct |
23 ms |
23800 KB |
Output is correct |
34 |
Correct |
23 ms |
23800 KB |
Output is correct |
35 |
Correct |
23 ms |
23800 KB |
Output is correct |
36 |
Correct |
24 ms |
23804 KB |
Output is correct |
37 |
Correct |
23 ms |
23928 KB |
Output is correct |
38 |
Correct |
24 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
34364 KB |
Output is correct |
2 |
Correct |
92 ms |
34424 KB |
Output is correct |
3 |
Correct |
67 ms |
30968 KB |
Output is correct |
4 |
Correct |
33 ms |
25336 KB |
Output is correct |
5 |
Correct |
30 ms |
24696 KB |
Output is correct |
6 |
Correct |
39 ms |
26232 KB |
Output is correct |
7 |
Correct |
23 ms |
23928 KB |
Output is correct |
8 |
Correct |
54 ms |
27640 KB |
Output is correct |
9 |
Correct |
63 ms |
29176 KB |
Output is correct |
10 |
Correct |
23 ms |
23928 KB |
Output is correct |
11 |
Correct |
81 ms |
31224 KB |
Output is correct |
12 |
Correct |
85 ms |
32632 KB |
Output is correct |
13 |
Correct |
23 ms |
23928 KB |
Output is correct |
14 |
Correct |
23 ms |
23800 KB |
Output is correct |
15 |
Correct |
23 ms |
23800 KB |
Output is correct |
16 |
Correct |
23 ms |
23928 KB |
Output is correct |
17 |
Correct |
23 ms |
23928 KB |
Output is correct |
18 |
Correct |
23 ms |
23928 KB |
Output is correct |
19 |
Correct |
23 ms |
23800 KB |
Output is correct |
20 |
Correct |
24 ms |
23800 KB |
Output is correct |
21 |
Correct |
24 ms |
23800 KB |
Output is correct |
22 |
Correct |
23 ms |
23800 KB |
Output is correct |
23 |
Correct |
23 ms |
23928 KB |
Output is correct |
24 |
Correct |
23 ms |
23800 KB |
Output is correct |
25 |
Correct |
23 ms |
23800 KB |
Output is correct |
26 |
Correct |
23 ms |
23800 KB |
Output is correct |
27 |
Correct |
28 ms |
23928 KB |
Output is correct |
28 |
Correct |
23 ms |
23800 KB |
Output is correct |
29 |
Correct |
23 ms |
23928 KB |
Output is correct |
30 |
Correct |
27 ms |
23868 KB |
Output is correct |
31 |
Correct |
23 ms |
23800 KB |
Output is correct |
32 |
Correct |
23 ms |
23928 KB |
Output is correct |
33 |
Correct |
23 ms |
23800 KB |
Output is correct |
34 |
Correct |
23 ms |
23800 KB |
Output is correct |
35 |
Correct |
23 ms |
23800 KB |
Output is correct |
36 |
Correct |
24 ms |
23804 KB |
Output is correct |
37 |
Correct |
23 ms |
23928 KB |
Output is correct |
38 |
Correct |
24 ms |
23900 KB |
Output is correct |
39 |
Correct |
93 ms |
34392 KB |
Output is correct |
40 |
Correct |
90 ms |
34284 KB |
Output is correct |
41 |
Correct |
81 ms |
31096 KB |
Output is correct |
42 |
Correct |
33 ms |
25340 KB |
Output is correct |
43 |
Correct |
24 ms |
23928 KB |
Output is correct |
44 |
Correct |
24 ms |
23928 KB |
Output is correct |
45 |
Correct |
27 ms |
23804 KB |
Output is correct |
46 |
Correct |
28 ms |
23800 KB |
Output is correct |
47 |
Correct |
27 ms |
23928 KB |
Output is correct |
48 |
Correct |
24 ms |
23800 KB |
Output is correct |
49 |
Correct |
24 ms |
23800 KB |
Output is correct |
50 |
Correct |
24 ms |
23800 KB |
Output is correct |
51 |
Correct |
24 ms |
23928 KB |
Output is correct |
52 |
Correct |
24 ms |
23800 KB |
Output is correct |
53 |
Correct |
28 ms |
23800 KB |
Output is correct |
54 |
Correct |
24 ms |
23928 KB |
Output is correct |
55 |
Correct |
24 ms |
23800 KB |
Output is correct |
56 |
Correct |
24 ms |
23800 KB |
Output is correct |
57 |
Correct |
105 ms |
31480 KB |
Output is correct |
58 |
Correct |
115 ms |
31592 KB |
Output is correct |
59 |
Correct |
105 ms |
31408 KB |
Output is correct |
60 |
Correct |
105 ms |
31480 KB |
Output is correct |
61 |
Correct |
104 ms |
31608 KB |
Output is correct |
62 |
Correct |
103 ms |
31608 KB |
Output is correct |
63 |
Correct |
96 ms |
31136 KB |
Output is correct |
64 |
Correct |
101 ms |
31352 KB |
Output is correct |
65 |
Correct |
102 ms |
31452 KB |
Output is correct |
66 |
Correct |
98 ms |
31480 KB |
Output is correct |
67 |
Correct |
103 ms |
31472 KB |
Output is correct |
68 |
Correct |
98 ms |
31480 KB |
Output is correct |
69 |
Correct |
105 ms |
31736 KB |
Output is correct |
70 |
Correct |
108 ms |
31836 KB |
Output is correct |
71 |
Correct |
24 ms |
23856 KB |
Output is correct |
72 |
Correct |
30 ms |
24056 KB |
Output is correct |
73 |
Correct |
25 ms |
24056 KB |
Output is correct |
74 |
Correct |
25 ms |
24184 KB |
Output is correct |
75 |
Correct |
25 ms |
24184 KB |
Output is correct |
76 |
Correct |
25 ms |
24056 KB |
Output is correct |
77 |
Correct |
30 ms |
24120 KB |
Output is correct |
78 |
Correct |
25 ms |
24060 KB |
Output is correct |
79 |
Correct |
25 ms |
24056 KB |
Output is correct |
80 |
Correct |
102 ms |
31612 KB |
Output is correct |
81 |
Correct |
111 ms |
31352 KB |
Output is correct |
82 |
Correct |
102 ms |
31612 KB |
Output is correct |
83 |
Correct |
103 ms |
31608 KB |
Output is correct |
84 |
Correct |
25 ms |
24056 KB |
Output is correct |
85 |
Correct |
25 ms |
23928 KB |
Output is correct |
86 |
Correct |
25 ms |
24056 KB |
Output is correct |
87 |
Correct |
25 ms |
24056 KB |
Output is correct |
88 |
Correct |
25 ms |
24060 KB |
Output is correct |
89 |
Correct |
25 ms |
24056 KB |
Output is correct |
90 |
Correct |
25 ms |
24056 KB |
Output is correct |
91 |
Correct |
25 ms |
24056 KB |
Output is correct |
92 |
Correct |
24 ms |
24056 KB |
Output is correct |
93 |
Correct |
25 ms |
24056 KB |
Output is correct |
94 |
Correct |
23 ms |
23928 KB |
Output is correct |
95 |
Correct |
23 ms |
23800 KB |
Output is correct |
96 |
Correct |
23 ms |
23928 KB |
Output is correct |
97 |
Correct |
23 ms |
23804 KB |
Output is correct |
98 |
Correct |
24 ms |
23928 KB |
Output is correct |
99 |
Correct |
23 ms |
23800 KB |
Output is correct |
100 |
Correct |
23 ms |
23800 KB |
Output is correct |
101 |
Correct |
23 ms |
23800 KB |
Output is correct |
102 |
Correct |
23 ms |
23800 KB |
Output is correct |
103 |
Correct |
23 ms |
23800 KB |
Output is correct |
104 |
Correct |
30 ms |
24824 KB |
Output is correct |
105 |
Correct |
38 ms |
26232 KB |
Output is correct |
106 |
Correct |
23 ms |
23928 KB |
Output is correct |
107 |
Correct |
55 ms |
27768 KB |
Output is correct |
108 |
Correct |
64 ms |
29208 KB |
Output is correct |
109 |
Correct |
24 ms |
23932 KB |
Output is correct |
110 |
Correct |
81 ms |
31140 KB |
Output is correct |
111 |
Correct |
88 ms |
32604 KB |
Output is correct |
112 |
Correct |
24 ms |
23928 KB |
Output is correct |
113 |
Correct |
125 ms |
35704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
28120 KB |
Output is correct |
2 |
Incorrect |
50 ms |
28024 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
34364 KB |
Output is correct |
2 |
Correct |
92 ms |
34424 KB |
Output is correct |
3 |
Correct |
67 ms |
30968 KB |
Output is correct |
4 |
Correct |
33 ms |
25336 KB |
Output is correct |
5 |
Correct |
30 ms |
24696 KB |
Output is correct |
6 |
Correct |
39 ms |
26232 KB |
Output is correct |
7 |
Correct |
23 ms |
23928 KB |
Output is correct |
8 |
Correct |
54 ms |
27640 KB |
Output is correct |
9 |
Correct |
63 ms |
29176 KB |
Output is correct |
10 |
Correct |
23 ms |
23928 KB |
Output is correct |
11 |
Correct |
81 ms |
31224 KB |
Output is correct |
12 |
Correct |
85 ms |
32632 KB |
Output is correct |
13 |
Correct |
23 ms |
23928 KB |
Output is correct |
14 |
Correct |
23 ms |
23928 KB |
Output is correct |
15 |
Correct |
25 ms |
23932 KB |
Output is correct |
16 |
Correct |
24 ms |
24056 KB |
Output is correct |
17 |
Correct |
24 ms |
23928 KB |
Output is correct |
18 |
Correct |
24 ms |
24056 KB |
Output is correct |
19 |
Correct |
25 ms |
24056 KB |
Output is correct |
20 |
Incorrect |
24 ms |
23928 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
34364 KB |
Output is correct |
2 |
Correct |
92 ms |
34424 KB |
Output is correct |
3 |
Correct |
67 ms |
30968 KB |
Output is correct |
4 |
Correct |
33 ms |
25336 KB |
Output is correct |
5 |
Correct |
30 ms |
24696 KB |
Output is correct |
6 |
Correct |
39 ms |
26232 KB |
Output is correct |
7 |
Correct |
23 ms |
23928 KB |
Output is correct |
8 |
Correct |
54 ms |
27640 KB |
Output is correct |
9 |
Correct |
63 ms |
29176 KB |
Output is correct |
10 |
Correct |
23 ms |
23928 KB |
Output is correct |
11 |
Correct |
81 ms |
31224 KB |
Output is correct |
12 |
Correct |
85 ms |
32632 KB |
Output is correct |
13 |
Correct |
23 ms |
23928 KB |
Output is correct |
14 |
Correct |
23 ms |
23800 KB |
Output is correct |
15 |
Correct |
23 ms |
23800 KB |
Output is correct |
16 |
Correct |
23 ms |
23928 KB |
Output is correct |
17 |
Correct |
23 ms |
23928 KB |
Output is correct |
18 |
Correct |
23 ms |
23928 KB |
Output is correct |
19 |
Correct |
23 ms |
23800 KB |
Output is correct |
20 |
Correct |
24 ms |
23800 KB |
Output is correct |
21 |
Correct |
24 ms |
23800 KB |
Output is correct |
22 |
Correct |
23 ms |
23800 KB |
Output is correct |
23 |
Correct |
23 ms |
23928 KB |
Output is correct |
24 |
Correct |
23 ms |
23800 KB |
Output is correct |
25 |
Correct |
23 ms |
23800 KB |
Output is correct |
26 |
Correct |
23 ms |
23800 KB |
Output is correct |
27 |
Correct |
28 ms |
23928 KB |
Output is correct |
28 |
Correct |
23 ms |
23800 KB |
Output is correct |
29 |
Correct |
23 ms |
23928 KB |
Output is correct |
30 |
Correct |
27 ms |
23868 KB |
Output is correct |
31 |
Correct |
23 ms |
23800 KB |
Output is correct |
32 |
Correct |
23 ms |
23928 KB |
Output is correct |
33 |
Correct |
23 ms |
23800 KB |
Output is correct |
34 |
Correct |
23 ms |
23800 KB |
Output is correct |
35 |
Correct |
23 ms |
23800 KB |
Output is correct |
36 |
Correct |
24 ms |
23804 KB |
Output is correct |
37 |
Correct |
23 ms |
23928 KB |
Output is correct |
38 |
Correct |
24 ms |
23900 KB |
Output is correct |
39 |
Correct |
93 ms |
34392 KB |
Output is correct |
40 |
Correct |
90 ms |
34284 KB |
Output is correct |
41 |
Correct |
81 ms |
31096 KB |
Output is correct |
42 |
Correct |
33 ms |
25340 KB |
Output is correct |
43 |
Correct |
24 ms |
23928 KB |
Output is correct |
44 |
Correct |
24 ms |
23928 KB |
Output is correct |
45 |
Correct |
27 ms |
23804 KB |
Output is correct |
46 |
Correct |
28 ms |
23800 KB |
Output is correct |
47 |
Correct |
27 ms |
23928 KB |
Output is correct |
48 |
Correct |
24 ms |
23800 KB |
Output is correct |
49 |
Correct |
24 ms |
23800 KB |
Output is correct |
50 |
Correct |
24 ms |
23800 KB |
Output is correct |
51 |
Correct |
24 ms |
23928 KB |
Output is correct |
52 |
Correct |
24 ms |
23800 KB |
Output is correct |
53 |
Correct |
28 ms |
23800 KB |
Output is correct |
54 |
Correct |
24 ms |
23928 KB |
Output is correct |
55 |
Correct |
24 ms |
23800 KB |
Output is correct |
56 |
Correct |
24 ms |
23800 KB |
Output is correct |
57 |
Correct |
105 ms |
31480 KB |
Output is correct |
58 |
Correct |
115 ms |
31592 KB |
Output is correct |
59 |
Correct |
105 ms |
31408 KB |
Output is correct |
60 |
Correct |
105 ms |
31480 KB |
Output is correct |
61 |
Correct |
104 ms |
31608 KB |
Output is correct |
62 |
Correct |
103 ms |
31608 KB |
Output is correct |
63 |
Correct |
96 ms |
31136 KB |
Output is correct |
64 |
Correct |
101 ms |
31352 KB |
Output is correct |
65 |
Correct |
102 ms |
31452 KB |
Output is correct |
66 |
Correct |
98 ms |
31480 KB |
Output is correct |
67 |
Correct |
103 ms |
31472 KB |
Output is correct |
68 |
Correct |
98 ms |
31480 KB |
Output is correct |
69 |
Correct |
105 ms |
31736 KB |
Output is correct |
70 |
Correct |
108 ms |
31836 KB |
Output is correct |
71 |
Correct |
24 ms |
23856 KB |
Output is correct |
72 |
Correct |
30 ms |
24056 KB |
Output is correct |
73 |
Correct |
25 ms |
24056 KB |
Output is correct |
74 |
Correct |
25 ms |
24184 KB |
Output is correct |
75 |
Correct |
25 ms |
24184 KB |
Output is correct |
76 |
Correct |
25 ms |
24056 KB |
Output is correct |
77 |
Correct |
30 ms |
24120 KB |
Output is correct |
78 |
Correct |
25 ms |
24060 KB |
Output is correct |
79 |
Correct |
25 ms |
24056 KB |
Output is correct |
80 |
Correct |
102 ms |
31612 KB |
Output is correct |
81 |
Correct |
111 ms |
31352 KB |
Output is correct |
82 |
Correct |
102 ms |
31612 KB |
Output is correct |
83 |
Correct |
103 ms |
31608 KB |
Output is correct |
84 |
Correct |
25 ms |
24056 KB |
Output is correct |
85 |
Correct |
25 ms |
23928 KB |
Output is correct |
86 |
Correct |
25 ms |
24056 KB |
Output is correct |
87 |
Correct |
25 ms |
24056 KB |
Output is correct |
88 |
Correct |
25 ms |
24060 KB |
Output is correct |
89 |
Correct |
25 ms |
24056 KB |
Output is correct |
90 |
Correct |
25 ms |
24056 KB |
Output is correct |
91 |
Correct |
25 ms |
24056 KB |
Output is correct |
92 |
Correct |
24 ms |
24056 KB |
Output is correct |
93 |
Correct |
25 ms |
24056 KB |
Output is correct |
94 |
Correct |
23 ms |
23928 KB |
Output is correct |
95 |
Correct |
23 ms |
23800 KB |
Output is correct |
96 |
Correct |
23 ms |
23928 KB |
Output is correct |
97 |
Correct |
23 ms |
23804 KB |
Output is correct |
98 |
Correct |
24 ms |
23928 KB |
Output is correct |
99 |
Correct |
23 ms |
23800 KB |
Output is correct |
100 |
Correct |
23 ms |
23800 KB |
Output is correct |
101 |
Correct |
23 ms |
23800 KB |
Output is correct |
102 |
Correct |
23 ms |
23800 KB |
Output is correct |
103 |
Correct |
23 ms |
23800 KB |
Output is correct |
104 |
Correct |
30 ms |
24824 KB |
Output is correct |
105 |
Correct |
38 ms |
26232 KB |
Output is correct |
106 |
Correct |
23 ms |
23928 KB |
Output is correct |
107 |
Correct |
55 ms |
27768 KB |
Output is correct |
108 |
Correct |
64 ms |
29208 KB |
Output is correct |
109 |
Correct |
24 ms |
23932 KB |
Output is correct |
110 |
Correct |
81 ms |
31140 KB |
Output is correct |
111 |
Correct |
88 ms |
32604 KB |
Output is correct |
112 |
Correct |
24 ms |
23928 KB |
Output is correct |
113 |
Correct |
125 ms |
35704 KB |
Output is correct |
114 |
Correct |
56 ms |
28120 KB |
Output is correct |
115 |
Incorrect |
50 ms |
28024 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |