// 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 travelTime(int n, int m, int L, int a[], int b[], int t[]){
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});
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
14712 KB |
Output is correct |
2 |
Correct |
60 ms |
14712 KB |
Output is correct |
3 |
Correct |
41 ms |
10744 KB |
Output is correct |
4 |
Correct |
9 ms |
4480 KB |
Output is correct |
5 |
Correct |
8 ms |
3712 KB |
Output is correct |
6 |
Correct |
15 ms |
5376 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
27 ms |
6908 KB |
Output is correct |
9 |
Correct |
36 ms |
8696 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
88 ms |
10744 KB |
Output is correct |
12 |
Correct |
83 ms |
12640 KB |
Output is correct |
13 |
Correct |
3 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
14712 KB |
Output is correct |
2 |
Correct |
60 ms |
14712 KB |
Output is correct |
3 |
Correct |
41 ms |
10744 KB |
Output is correct |
4 |
Correct |
9 ms |
4480 KB |
Output is correct |
5 |
Correct |
8 ms |
3712 KB |
Output is correct |
6 |
Correct |
15 ms |
5376 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
27 ms |
6908 KB |
Output is correct |
9 |
Correct |
36 ms |
8696 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
88 ms |
10744 KB |
Output is correct |
12 |
Correct |
83 ms |
12640 KB |
Output is correct |
13 |
Correct |
3 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 |
2720 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
2 ms |
2688 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 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 |
3 ms |
2688 KB |
Output is correct |
28 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
14712 KB |
Output is correct |
2 |
Correct |
60 ms |
14712 KB |
Output is correct |
3 |
Correct |
41 ms |
10744 KB |
Output is correct |
4 |
Correct |
9 ms |
4480 KB |
Output is correct |
5 |
Correct |
8 ms |
3712 KB |
Output is correct |
6 |
Correct |
15 ms |
5376 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
27 ms |
6908 KB |
Output is correct |
9 |
Correct |
36 ms |
8696 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
88 ms |
10744 KB |
Output is correct |
12 |
Correct |
83 ms |
12640 KB |
Output is correct |
13 |
Correct |
3 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 |
2720 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
2 ms |
2688 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 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 |
3 ms |
2688 KB |
Output is correct |
28 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
7024 KB |
Output is correct |
2 |
Correct |
36 ms |
7064 KB |
Output is correct |
3 |
Correct |
29 ms |
7212 KB |
Output is correct |
4 |
Correct |
32 ms |
7040 KB |
Output is correct |
5 |
Correct |
28 ms |
7040 KB |
Output is correct |
6 |
Correct |
33 ms |
7592 KB |
Output is correct |
7 |
Correct |
29 ms |
7160 KB |
Output is correct |
8 |
Correct |
28 ms |
6904 KB |
Output is correct |
9 |
Correct |
28 ms |
6912 KB |
Output is correct |
10 |
Correct |
38 ms |
7160 KB |
Output is correct |
11 |
Correct |
2 ms |
2816 KB |
Output is correct |
12 |
Correct |
7 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 |
7 ms |
4664 KB |
Output is correct |
16 |
Correct |
6 ms |
4604 KB |
Output is correct |
17 |
Correct |
6 ms |
4220 KB |
Output is correct |
18 |
Correct |
6 ms |
4732 KB |
Output is correct |
19 |
Correct |
7 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
14712 KB |
Output is correct |
2 |
Correct |
60 ms |
14712 KB |
Output is correct |
3 |
Correct |
41 ms |
10744 KB |
Output is correct |
4 |
Correct |
9 ms |
4480 KB |
Output is correct |
5 |
Correct |
8 ms |
3712 KB |
Output is correct |
6 |
Correct |
15 ms |
5376 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
27 ms |
6908 KB |
Output is correct |
9 |
Correct |
36 ms |
8696 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
88 ms |
10744 KB |
Output is correct |
12 |
Correct |
83 ms |
12640 KB |
Output is correct |
13 |
Correct |
3 ms |
2816 KB |
Output is correct |
14 |
Correct |
3 ms |
2816 KB |
Output is correct |
15 |
Correct |
3 ms |
2816 KB |
Output is correct |
16 |
Correct |
5 ms |
2944 KB |
Output is correct |
17 |
Correct |
2 ms |
2816 KB |
Output is correct |
18 |
Correct |
3 ms |
2816 KB |
Output is correct |
19 |
Correct |
3 ms |
2944 KB |
Output is correct |
20 |
Correct |
2 ms |
2816 KB |
Output is correct |
21 |
Correct |
3 ms |
2816 KB |
Output is correct |
22 |
Correct |
4 ms |
2944 KB |
Output is correct |
23 |
Correct |
3 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
14712 KB |
Output is correct |
2 |
Correct |
60 ms |
14712 KB |
Output is correct |
3 |
Correct |
41 ms |
10744 KB |
Output is correct |
4 |
Correct |
9 ms |
4480 KB |
Output is correct |
5 |
Correct |
8 ms |
3712 KB |
Output is correct |
6 |
Correct |
15 ms |
5376 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
27 ms |
6908 KB |
Output is correct |
9 |
Correct |
36 ms |
8696 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
88 ms |
10744 KB |
Output is correct |
12 |
Correct |
83 ms |
12640 KB |
Output is correct |
13 |
Correct |
3 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 |
2720 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
2 ms |
2688 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 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 |
3 ms |
2688 KB |
Output is correct |
28 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |