#include "dreaming.h"
#include <bits/stdc++.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=0; 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
11256 KB |
Output is correct |
2 |
Correct |
66 ms |
11384 KB |
Output is correct |
3 |
Correct |
42 ms |
8312 KB |
Output is correct |
4 |
Correct |
11 ms |
3968 KB |
Output is correct |
5 |
Correct |
10 ms |
3448 KB |
Output is correct |
6 |
Correct |
18 ms |
4608 KB |
Output is correct |
7 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
11256 KB |
Output is correct |
2 |
Correct |
66 ms |
11384 KB |
Output is correct |
3 |
Correct |
42 ms |
8312 KB |
Output is correct |
4 |
Correct |
11 ms |
3968 KB |
Output is correct |
5 |
Correct |
10 ms |
3448 KB |
Output is correct |
6 |
Correct |
18 ms |
4608 KB |
Output is correct |
7 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
11256 KB |
Output is correct |
2 |
Correct |
66 ms |
11384 KB |
Output is correct |
3 |
Correct |
42 ms |
8312 KB |
Output is correct |
4 |
Correct |
11 ms |
3968 KB |
Output is correct |
5 |
Correct |
10 ms |
3448 KB |
Output is correct |
6 |
Correct |
18 ms |
4608 KB |
Output is correct |
7 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
5848 KB |
Output is correct |
2 |
Correct |
29 ms |
5880 KB |
Output is correct |
3 |
Correct |
28 ms |
5888 KB |
Output is correct |
4 |
Correct |
28 ms |
5880 KB |
Output is correct |
5 |
Correct |
27 ms |
5884 KB |
Output is correct |
6 |
Correct |
32 ms |
6268 KB |
Output is correct |
7 |
Correct |
35 ms |
6044 KB |
Output is correct |
8 |
Correct |
27 ms |
5760 KB |
Output is correct |
9 |
Correct |
26 ms |
5760 KB |
Output is correct |
10 |
Correct |
30 ms |
6008 KB |
Output is correct |
11 |
Correct |
4 ms |
2688 KB |
Output is correct |
12 |
Correct |
8 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 |
8 ms |
3836 KB |
Output is correct |
16 |
Correct |
7 ms |
3836 KB |
Output is correct |
17 |
Correct |
7 ms |
3708 KB |
Output is correct |
18 |
Correct |
9 ms |
3836 KB |
Output is correct |
19 |
Correct |
8 ms |
3836 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 |
2688 KB |
Output is correct |
23 |
Correct |
7 ms |
3836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
11256 KB |
Output is correct |
2 |
Correct |
66 ms |
11384 KB |
Output is correct |
3 |
Correct |
42 ms |
8312 KB |
Output is correct |
4 |
Correct |
11 ms |
3968 KB |
Output is correct |
5 |
Correct |
10 ms |
3448 KB |
Output is correct |
6 |
Correct |
18 ms |
4608 KB |
Output is correct |
7 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
11256 KB |
Output is correct |
2 |
Correct |
66 ms |
11384 KB |
Output is correct |
3 |
Correct |
42 ms |
8312 KB |
Output is correct |
4 |
Correct |
11 ms |
3968 KB |
Output is correct |
5 |
Correct |
10 ms |
3448 KB |
Output is correct |
6 |
Correct |
18 ms |
4608 KB |
Output is correct |
7 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |