#include"dreaming.h"
//#include"grader.c"
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
vector<pair<int,int>>g[100005];
bool vis[100005];
int diam,mx[100005],mm,id;
void dfs(int v,int p,int depth){
mx[v]=max(mx[v],depth);
if(depth>mm){
mm=depth;
id=v;
}
for(auto to:g[v])if(to.fr!=p)dfs(to.fr,v,depth+to.sc);
}
void go(int v,int p){
mm=min(mm,mx[v]);
diam=max(diam,mx[v]);
for(auto to:g[v])if(to.fr!=p)go(to.fr,v);
}
int travelTime(int n,int m,int l,int x[],int y[],int z[]){
for(int i=0;i<m;i++){
g[x[i]].push_back({y[i],z[i]});
g[y[i]].push_back({x[i],z[i]});
}
vector<int>st;
for(int i=0;i<n;i++)if(!vis[i]){
mm=0;
dfs(i,i,0);
mm=0;
dfs(id,id,0);
mm=0;
dfs(id,id,0);
mm=2e9;
go(i,i);
st.push_back(mm);
}
sort(st.begin(),st.end(),greater<int>());
if(st.size()==1)return diam;
else if(st.size()==2)return max(diam,st[0]+st[1]+l);
else return max(diam,max(st[0]+st[1]+l,st[1]+st[2]+2*l));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1059 ms |
11256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1059 ms |
11256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1059 ms |
11256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
6016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1059 ms |
11256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1059 ms |
11256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |