#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;
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(f,f);
int b=f;
if(a==b){
vec.push_back(0);
return;
}
int cur=b,d=0;
while(b!=a){
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());
int ans=vec[0];
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 |
Incorrect |
47 ms |
13644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
47 ms |
13644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
6744 KB |
Output is correct |
2 |
Correct |
21 ms |
6792 KB |
Output is correct |
3 |
Correct |
21 ms |
6836 KB |
Output is correct |
4 |
Correct |
21 ms |
6804 KB |
Output is correct |
5 |
Correct |
21 ms |
6812 KB |
Output is correct |
6 |
Correct |
22 ms |
7292 KB |
Output is correct |
7 |
Correct |
24 ms |
6912 KB |
Output is correct |
8 |
Correct |
21 ms |
6744 KB |
Output is correct |
9 |
Correct |
19 ms |
6740 KB |
Output is correct |
10 |
Correct |
18 ms |
6976 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
4 ms |
4816 KB |
Output is correct |
13 |
Correct |
4 ms |
4816 KB |
Output is correct |
14 |
Correct |
5 ms |
4688 KB |
Output is correct |
15 |
Correct |
6 ms |
4812 KB |
Output is correct |
16 |
Correct |
5 ms |
4688 KB |
Output is correct |
17 |
Correct |
4 ms |
4176 KB |
Output is correct |
18 |
Correct |
5 ms |
4816 KB |
Output is correct |
19 |
Correct |
4 ms |
4688 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
5 ms |
4688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
47 ms |
13644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |