#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 ans;
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 D,f;
void dfs(int x, int p, 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,d+it.sc);
}
}
int find(int x){
D=0,f=x;
dfs(x,x,0);
D=0;
int F=f;
dfs(f,f,0);
ans=1e9;
//cout<<x<<' '<<D<<endl;
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);
}
}
/*for(auto it: vec) cout<<it<<' ';
cout<<endl;*/
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 |
61 ms |
13952 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 |
61 ms |
13952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
5720 KB |
Output is correct |
2 |
Correct |
29 ms |
5740 KB |
Output is correct |
3 |
Correct |
32 ms |
5716 KB |
Output is correct |
4 |
Correct |
28 ms |
5716 KB |
Output is correct |
5 |
Correct |
42 ms |
5668 KB |
Output is correct |
6 |
Correct |
43 ms |
6100 KB |
Output is correct |
7 |
Correct |
28 ms |
5804 KB |
Output is correct |
8 |
Correct |
25 ms |
5668 KB |
Output is correct |
9 |
Correct |
27 ms |
5684 KB |
Output is correct |
10 |
Correct |
23 ms |
5844 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
4 ms |
3664 KB |
Output is correct |
13 |
Correct |
4 ms |
3664 KB |
Output is correct |
14 |
Correct |
4 ms |
3664 KB |
Output is correct |
15 |
Correct |
4 ms |
3664 KB |
Output is correct |
16 |
Correct |
4 ms |
3664 KB |
Output is correct |
17 |
Correct |
4 ms |
3536 KB |
Output is correct |
18 |
Correct |
5 ms |
3664 KB |
Output is correct |
19 |
Correct |
5 ms |
3664 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 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 |
61 ms |
13952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |