#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
const int N=1e5+5;
vector<pair<int,int>> g[N];
int used[N],d[N];
pair<int,int> par[N];
vector<int> vec;
int ans=0;
int D,f;
void dfs(int x, int p){
used[x]=1;
if(p==x){
d[x]=0;
D=0,f=x;
}
else{
if(d[x]>D){
D=d[x];
f=x;
}
}
for(auto it: g[x]){
if(it.fr==p) continue;
d[it.fr]=it.sc+d[x];
par[it.fr]={x,it.sc};
dfs(it.fr,x);
}
}
void find(int x){
dfs(x,x);
int a=f;
dfs(a,a);
int b=f;
ans=max(ans,D);
if(a==b){
vec.push_back(0);
return;
}
int cur=b,d=0;
while(true){
int last=d;
d+=par[cur].sc;
cur=par[cur].fr;
if(2*d>=D){
vec.push_back({D-last});
return;
}
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i=0;i<M;i++){
g[A[i]].push_back({B[i],T[i]});
g[B[i]].push_back({A[i],T[i]});
}
for(int i=0;i<N;i++){
if(!used[i]){
find(i);
}
}
sort(vec.rbegin(),vec.rend());
if(vec.size()>1)
ans=max(ans,vec[0]+vec[1]+L);
if(vec.size()>2)
ans=max(ans,vec[1]+vec[2]+L+L);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
13692 KB |
Output is correct |
2 |
Correct |
63 ms |
14924 KB |
Output is correct |
3 |
Correct |
40 ms |
10812 KB |
Output is correct |
4 |
Correct |
8 ms |
4488 KB |
Output is correct |
5 |
Correct |
6 ms |
3668 KB |
Output is correct |
6 |
Correct |
13 ms |
5360 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2644 KB |
Output is correct |
4 |
Incorrect |
3 ms |
2644 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
13692 KB |
Output is correct |
2 |
Correct |
63 ms |
14924 KB |
Output is correct |
3 |
Correct |
40 ms |
10812 KB |
Output is correct |
4 |
Correct |
8 ms |
4488 KB |
Output is correct |
5 |
Correct |
6 ms |
3668 KB |
Output is correct |
6 |
Correct |
13 ms |
5360 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
6772 KB |
Output is correct |
2 |
Correct |
44 ms |
6788 KB |
Output is correct |
3 |
Correct |
31 ms |
6724 KB |
Output is correct |
4 |
Correct |
34 ms |
6856 KB |
Output is correct |
5 |
Correct |
28 ms |
6804 KB |
Output is correct |
6 |
Correct |
33 ms |
7256 KB |
Output is correct |
7 |
Correct |
41 ms |
6992 KB |
Output is correct |
8 |
Correct |
30 ms |
6740 KB |
Output is correct |
9 |
Correct |
39 ms |
6716 KB |
Output is correct |
10 |
Correct |
28 ms |
6996 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
6 ms |
4816 KB |
Output is correct |
13 |
Correct |
7 ms |
4816 KB |
Output is correct |
14 |
Correct |
7 ms |
4680 KB |
Output is correct |
15 |
Correct |
6 ms |
4816 KB |
Output is correct |
16 |
Correct |
6 ms |
4688 KB |
Output is correct |
17 |
Correct |
5 ms |
4176 KB |
Output is correct |
18 |
Correct |
6 ms |
4816 KB |
Output is correct |
19 |
Correct |
7 ms |
4688 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
7 ms |
4688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2644 KB |
Output is correct |
4 |
Incorrect |
3 ms |
2644 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
13692 KB |
Output is correct |
2 |
Correct |
63 ms |
14924 KB |
Output is correct |
3 |
Correct |
40 ms |
10812 KB |
Output is correct |
4 |
Correct |
8 ms |
4488 KB |
Output is correct |
5 |
Correct |
6 ms |
3668 KB |
Output is correct |
6 |
Correct |
13 ms |
5360 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |