#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];
return rads[0] + rads[1] + L;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
11908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
11908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
6092 KB |
Output is correct |
2 |
Incorrect |
20 ms |
6100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
11908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |