#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];
int D,f,ans;
void dfs(int x, int p, int y, int d){
used[x]=1;
if(d>D){
f=x;
D=d;
}
for(auto it: g[x]){
if(it.fr==p) continue;
dfs(it.fr,x,y,d+it.sc);
}
}
int get(int x, int y, int p, int D, int d){
if(x==y){
ans=min(ans,max(D,d));
return 1;
}
for(auto it: g[x]){
if(it.fr==p) continue;
if(get(it.fr,y,x,D-it.sc,d+it.sc)){
ans=min(ans,max(D,d));
return 1;
}
}
return 0;
}
int find(int x){
D=0,f=x;
dfs(x,x,-1,0);
D=0;
int F=f;
dfs(f,f,-1,0);
ans=1e9;
get(f,F,-1,D,0);
return ans;
}
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]});
}
vector<int> vec;
for(int i=0;i<N;i++){
if(!used[i]){
int c=find(i);
vec.push_back(c);
}
}
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;
}
/*int main(){
int n,m,l;cin>>n>>m>>l;
int a[m]{},b[m]{},t[m]{};
for(int i=0;i<m;i++){
cin>>a[i]>>b[i]>>t[i];
}
cout<<travelTime(n,m,l,a,b,t);
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
15232 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 |
48 ms |
15232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
6092 KB |
Output is correct |
2 |
Correct |
20 ms |
6056 KB |
Output is correct |
3 |
Correct |
19 ms |
6104 KB |
Output is correct |
4 |
Correct |
25 ms |
6132 KB |
Output is correct |
5 |
Correct |
22 ms |
6076 KB |
Output is correct |
6 |
Correct |
33 ms |
6572 KB |
Output is correct |
7 |
Correct |
27 ms |
6316 KB |
Output is correct |
8 |
Correct |
19 ms |
6100 KB |
Output is correct |
9 |
Correct |
21 ms |
5980 KB |
Output is correct |
10 |
Correct |
23 ms |
6236 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
4 ms |
3664 KB |
Output is correct |
13 |
Correct |
5 ms |
3664 KB |
Output is correct |
14 |
Correct |
4 ms |
3664 KB |
Output is correct |
15 |
Correct |
5 ms |
3664 KB |
Output is correct |
16 |
Correct |
5 ms |
3664 KB |
Output is correct |
17 |
Correct |
4 ms |
3544 KB |
Output is correct |
18 |
Correct |
7 ms |
3664 KB |
Output is correct |
19 |
Correct |
5 ms |
3664 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 |
5 ms |
3664 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 |
48 ms |
15232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |