#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int rd[100000];
bool vis[100000];
struct W {
int t;
int w;
};
vector<vector<W>> al;
void calcrd(int v, int p) {
vis[v] = true;
int mrd = 0;
for(auto a : al[v]) {
if(a.t == p) continue;
calcrd(a.t, v);
mrd = max(mrd, a.w + rd[a.t]);
}
rd[v] = mrd;
}
int radius(int v, int p, int tdist) {
int mr = tdist;
int mr2 = tdist;
for(auto a : al[v]) {
if(a.t == p) continue;
if(rd[a.t] + a.w >= mr) {
mr2 = mr;
mr = rd[a.t] + a.w;
} else if(rd[a.t] + a.w >= mr2) {
mr2 = rd[a.t] + a.w;
}
}
int br = mr;
for(auto a : al[v]) {
if(a.t == p) continue;
if(rd[a.t] + a.w == mr) {
br = min(br, radius(a.t, v, mr2 + a.w));
} else {
br = min(br, radius(a.t, v, mr + a.w));
}
}
return br;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
al.assign(N, {});
for(int i = 0; i < M; ++i) {
al[A[i]].push_back({B[i], T[i]});
al[B[i]].push_back({A[i], T[i]});
}
vector<int> rads;
for(int i = 0; i < N; ++i) {
if(vis[i]) continue;
calcrd(i, i);
rads.push_back(radius(i, i, 0));
}
sort(rbegin(rads), rend(rads));
if(rads.size() == 1) return rads[0];
if(rads.size() == 2) return rads[0] + L + rads[1];
return max(rads[0] + rads[1] + L, rads[1] + 2*L + rads[2]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
10700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
10700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
5592 KB |
Output is correct |
2 |
Correct |
17 ms |
5644 KB |
Output is correct |
3 |
Correct |
21 ms |
6088 KB |
Output is correct |
4 |
Correct |
20 ms |
6076 KB |
Output is correct |
5 |
Correct |
26 ms |
6060 KB |
Output is correct |
6 |
Correct |
20 ms |
6608 KB |
Output is correct |
7 |
Correct |
20 ms |
6348 KB |
Output is correct |
8 |
Correct |
27 ms |
5900 KB |
Output is correct |
9 |
Correct |
18 ms |
5920 KB |
Output is correct |
10 |
Correct |
19 ms |
6228 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
5 ms |
3792 KB |
Output is correct |
13 |
Correct |
4 ms |
3776 KB |
Output is correct |
14 |
Correct |
5 ms |
3792 KB |
Output is correct |
15 |
Correct |
4 ms |
3792 KB |
Output is correct |
16 |
Correct |
4 ms |
3764 KB |
Output is correct |
17 |
Correct |
4 ms |
3664 KB |
Output is correct |
18 |
Correct |
4 ms |
3792 KB |
Output is correct |
19 |
Correct |
5 ms |
3764 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
440 KB |
Output is correct |
23 |
Correct |
4 ms |
3764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
10700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |