#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
typedef struct {int to, cost;} edge;
vector<edge> G[100010];
vector<int> rad;
bool done[100010];
int N, M, L, tmp, sz[100010], u, D;
int dfs(int v){
done[v]=true, sz[v]=1;
for(auto& e:G[v])
if(!done[e.to]) sz[v]+=dfs(e.to);
return sz[v];
}
int findcen(int v){
dfs(v);
int now=v;
bool iscen=false;
while(!iscen){
iscen=true;
for(auto& e:G[now])
if(sz[now]>sz[e.to]&&sz[e.to]>sz[v]/2){
iscen=false, now=e.to;
break;
}
}
return now;
}
void find(int v, int p=-1, int d=0){
if(tmp<=d) tmp=d, u=v;
for(auto& e:G[v])
if(e.to!=p) find(e.to, v, d+e.cost);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
for(int i=1; i<=M; i++){
G[A[i]+1].push_back({B[i]+1, T[i]});
G[B[i]+1].push_back({A[i]+1, T[i]});
}
for(int i=1; i<=N; i++)
if(!done[i]){
int c=findcen(i);
tmp=0, find(c), rad.push_back(tmp);
tmp=0, find(u), D=max(D, tmp);
}
sort(rad.begin(), rad.end(), greater<int>());
if(rad.size()>1U) D=max(D, rad[0]+rad[1]+L);
if(rad.size()>2U) D=max(D, rad[1]+rad[2]+2*L);
return D;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
11768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
11768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
11768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
5888 KB |
Output is correct |
2 |
Correct |
25 ms |
5888 KB |
Output is correct |
3 |
Correct |
34 ms |
5884 KB |
Output is correct |
4 |
Correct |
32 ms |
5888 KB |
Output is correct |
5 |
Correct |
30 ms |
5908 KB |
Output is correct |
6 |
Correct |
37 ms |
6272 KB |
Output is correct |
7 |
Correct |
31 ms |
6008 KB |
Output is correct |
8 |
Correct |
28 ms |
6016 KB |
Output is correct |
9 |
Correct |
25 ms |
5760 KB |
Output is correct |
10 |
Correct |
38 ms |
6008 KB |
Output is correct |
11 |
Correct |
4 ms |
2688 KB |
Output is correct |
12 |
Correct |
7 ms |
3836 KB |
Output is correct |
13 |
Correct |
8 ms |
3836 KB |
Output is correct |
14 |
Correct |
7 ms |
3836 KB |
Output is correct |
15 |
Correct |
7 ms |
3836 KB |
Output is correct |
16 |
Correct |
7 ms |
3836 KB |
Output is correct |
17 |
Correct |
8 ms |
3836 KB |
Output is correct |
18 |
Correct |
8 ms |
3964 KB |
Output is correct |
19 |
Correct |
7 ms |
3808 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2816 KB |
Output is correct |
23 |
Correct |
7 ms |
3836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
11768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
11768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |