// And you curse yourself for things you never done
#include<bits/stdc++.h>
#include "dreaming.h"
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
vector<pii> v[maxn];
int pr[maxn], prv[maxn], h[maxn];
bool mark[maxn];
int far(int u, int par = -1){
mark[u] = 1;
if(par == -1)
h[u] = 0;
int ans = u;
for(pii p : v[u]){
int y = p.F, c = p.S;
if(y != par){
h[y] = h[u] + c;
pr[y] = u;
prv[y] = c;
int x = far(y, u);
if(h[x] > h[ans])
ans = x;
}
}
return ans;
}
int TIME = 0;
int travelTime(int n, int m, int L, int a[], int b[], int t[]){
assert(++TIME <= 1);
for(int i = 0; i < m; i++){
v[a[i]].PB({b[i], t[i]});
v[b[i]].PB({a[i], t[i]});
}
int ans = 0;
vector<int> vec;
for(int i = 0; i < n; i++){
if(!mark[i]){
int A = far(i), B = far(A);
int tmp = B, tmpv = 0, LST = -1;
ans = max(ans, h[B]);
while(tmpv + tmpv < h[B]){
LST = prv[tmp];
tmpv+= prv[tmp];
tmp = pr[tmp];
}
tmpv = min(tmpv, h[B] - tmpv + LST);
vec.PB(tmpv);
}
}
if(sz(vec) == 1)
return ans;
if(sz(vec) == 2)
return max(ans, vec[0] + vec[1] + L);
sort(vec.begin(), vec.end());
int A = vec[sz(vec)-3], B = vec[sz(vec)-2], C = vec[sz(vec)-1];
return max({ans, L + B + C, L + L + A + B});
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
13560 KB |
Output is correct |
2 |
Correct |
63 ms |
13432 KB |
Output is correct |
3 |
Correct |
43 ms |
9724 KB |
Output is correct |
4 |
Correct |
12 ms |
4224 KB |
Output is correct |
5 |
Correct |
7 ms |
3584 KB |
Output is correct |
6 |
Correct |
15 ms |
4992 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
28 ms |
6392 KB |
Output is correct |
9 |
Correct |
39 ms |
7936 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
63 ms |
9532 KB |
Output is correct |
12 |
Correct |
71 ms |
11512 KB |
Output is correct |
13 |
Correct |
2 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
13560 KB |
Output is correct |
2 |
Correct |
63 ms |
13432 KB |
Output is correct |
3 |
Correct |
43 ms |
9724 KB |
Output is correct |
4 |
Correct |
12 ms |
4224 KB |
Output is correct |
5 |
Correct |
7 ms |
3584 KB |
Output is correct |
6 |
Correct |
15 ms |
4992 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
28 ms |
6392 KB |
Output is correct |
9 |
Correct |
39 ms |
7936 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
63 ms |
9532 KB |
Output is correct |
12 |
Correct |
71 ms |
11512 KB |
Output is correct |
13 |
Correct |
2 ms |
2816 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
2 ms |
2816 KB |
Output is correct |
19 |
Correct |
2 ms |
2816 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Correct |
2 ms |
2688 KB |
Output is correct |
22 |
Correct |
2 ms |
2688 KB |
Output is correct |
23 |
Correct |
2 ms |
2688 KB |
Output is correct |
24 |
Correct |
2 ms |
2688 KB |
Output is correct |
25 |
Correct |
2 ms |
2688 KB |
Output is correct |
26 |
Correct |
2 ms |
2688 KB |
Output is correct |
27 |
Correct |
2 ms |
2688 KB |
Output is correct |
28 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
13560 KB |
Output is correct |
2 |
Correct |
63 ms |
13432 KB |
Output is correct |
3 |
Correct |
43 ms |
9724 KB |
Output is correct |
4 |
Correct |
12 ms |
4224 KB |
Output is correct |
5 |
Correct |
7 ms |
3584 KB |
Output is correct |
6 |
Correct |
15 ms |
4992 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
28 ms |
6392 KB |
Output is correct |
9 |
Correct |
39 ms |
7936 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
63 ms |
9532 KB |
Output is correct |
12 |
Correct |
71 ms |
11512 KB |
Output is correct |
13 |
Correct |
2 ms |
2816 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
2 ms |
2816 KB |
Output is correct |
19 |
Correct |
2 ms |
2816 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Correct |
2 ms |
2688 KB |
Output is correct |
22 |
Correct |
2 ms |
2688 KB |
Output is correct |
23 |
Correct |
2 ms |
2688 KB |
Output is correct |
24 |
Correct |
2 ms |
2688 KB |
Output is correct |
25 |
Correct |
2 ms |
2688 KB |
Output is correct |
26 |
Correct |
2 ms |
2688 KB |
Output is correct |
27 |
Correct |
2 ms |
2688 KB |
Output is correct |
28 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
6692 KB |
Output is correct |
2 |
Correct |
29 ms |
6656 KB |
Output is correct |
3 |
Correct |
29 ms |
6520 KB |
Output is correct |
4 |
Correct |
27 ms |
6656 KB |
Output is correct |
5 |
Correct |
30 ms |
6520 KB |
Output is correct |
6 |
Correct |
29 ms |
7040 KB |
Output is correct |
7 |
Correct |
30 ms |
6776 KB |
Output is correct |
8 |
Correct |
35 ms |
6520 KB |
Output is correct |
9 |
Correct |
26 ms |
6528 KB |
Output is correct |
10 |
Correct |
27 ms |
6784 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
6 ms |
4604 KB |
Output is correct |
13 |
Correct |
6 ms |
4604 KB |
Output is correct |
14 |
Correct |
6 ms |
4604 KB |
Output is correct |
15 |
Correct |
6 ms |
4604 KB |
Output is correct |
16 |
Correct |
6 ms |
4604 KB |
Output is correct |
17 |
Correct |
5 ms |
4220 KB |
Output is correct |
18 |
Correct |
6 ms |
4604 KB |
Output is correct |
19 |
Correct |
6 ms |
4604 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
13560 KB |
Output is correct |
2 |
Correct |
63 ms |
13432 KB |
Output is correct |
3 |
Correct |
43 ms |
9724 KB |
Output is correct |
4 |
Correct |
12 ms |
4224 KB |
Output is correct |
5 |
Correct |
7 ms |
3584 KB |
Output is correct |
6 |
Correct |
15 ms |
4992 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
28 ms |
6392 KB |
Output is correct |
9 |
Correct |
39 ms |
7936 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
63 ms |
9532 KB |
Output is correct |
12 |
Correct |
71 ms |
11512 KB |
Output is correct |
13 |
Correct |
2 ms |
2816 KB |
Output is correct |
14 |
Correct |
3 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2816 KB |
Output is correct |
16 |
Correct |
3 ms |
2816 KB |
Output is correct |
17 |
Correct |
3 ms |
2688 KB |
Output is correct |
18 |
Correct |
3 ms |
2816 KB |
Output is correct |
19 |
Correct |
3 ms |
2816 KB |
Output is correct |
20 |
Correct |
2 ms |
2816 KB |
Output is correct |
21 |
Correct |
4 ms |
2816 KB |
Output is correct |
22 |
Correct |
3 ms |
2816 KB |
Output is correct |
23 |
Correct |
2 ms |
2688 KB |
Output is correct |
24 |
Correct |
2 ms |
2688 KB |
Output is correct |
25 |
Correct |
2 ms |
2688 KB |
Output is correct |
26 |
Correct |
2 ms |
2688 KB |
Output is correct |
27 |
Correct |
2 ms |
2688 KB |
Output is correct |
28 |
Correct |
2 ms |
2688 KB |
Output is correct |
29 |
Correct |
2 ms |
2688 KB |
Output is correct |
30 |
Correct |
2 ms |
2688 KB |
Output is correct |
31 |
Correct |
2 ms |
2688 KB |
Output is correct |
32 |
Correct |
2 ms |
2688 KB |
Output is correct |
33 |
Correct |
2 ms |
2688 KB |
Output is correct |
34 |
Correct |
2 ms |
2688 KB |
Output is correct |
35 |
Correct |
2 ms |
2688 KB |
Output is correct |
36 |
Correct |
2 ms |
2688 KB |
Output is correct |
37 |
Correct |
2 ms |
2688 KB |
Output is correct |
38 |
Correct |
2 ms |
2688 KB |
Output is correct |
39 |
Correct |
2 ms |
2688 KB |
Output is correct |
40 |
Correct |
2 ms |
2688 KB |
Output is correct |
41 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
13560 KB |
Output is correct |
2 |
Correct |
63 ms |
13432 KB |
Output is correct |
3 |
Correct |
43 ms |
9724 KB |
Output is correct |
4 |
Correct |
12 ms |
4224 KB |
Output is correct |
5 |
Correct |
7 ms |
3584 KB |
Output is correct |
6 |
Correct |
15 ms |
4992 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
28 ms |
6392 KB |
Output is correct |
9 |
Correct |
39 ms |
7936 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
63 ms |
9532 KB |
Output is correct |
12 |
Correct |
71 ms |
11512 KB |
Output is correct |
13 |
Correct |
2 ms |
2816 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
2 ms |
2816 KB |
Output is correct |
19 |
Correct |
2 ms |
2816 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Correct |
2 ms |
2688 KB |
Output is correct |
22 |
Correct |
2 ms |
2688 KB |
Output is correct |
23 |
Correct |
2 ms |
2688 KB |
Output is correct |
24 |
Correct |
2 ms |
2688 KB |
Output is correct |
25 |
Correct |
2 ms |
2688 KB |
Output is correct |
26 |
Correct |
2 ms |
2688 KB |
Output is correct |
27 |
Correct |
2 ms |
2688 KB |
Output is correct |
28 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |