#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=1e5+5;
int n,m,color[mxn],mx,node,node2,res,l[mxn];
vector<pii>vt[mxn];
void dfs(int u,int p,int dis){
if(dis>=mx){
mx=dis;
node=u;
}
color[u]=1;
for(pii v:vt[u]){
if(v.F!=p){
dfs(v.F,u,dis+v.S);
}
}
}
void dfs2(int u,int p,int dis){
l[u]=dis;
if(dis>=mx){
mx=dis;
node2=u;
}
for(pii v:vt[u]){
if(v.F!=p){
dfs2(v.F,u,dis+v.S);
}
}
}
bool dfs3(int u,int p,int dis){
int q=0;
if(u==node) q=1;
for(pii v:vt[u]){
if(v.F!=p&&dfs3(v.F,u,dis+v.S)){
q=1;
res=min(res,max(l[v.F],dis+v.S));
}
}
return q;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
n=N,m=M;
for(int i=0;i<m;i++){
vt[A[i]+1].pb({B[i]+1,T[i]});
vt[B[i]+1].pb({A[i]+1,T[i]});
}
vector<int>vtt;
for(int i=1;i<=n;i++){
if(color[i]) continue;
mx=0,node=0;
dfs(i,-1,0);
mx=0,node2=0;
dfs2(node,-1,0);
res=mx;
dfs3(node2,-1,0);
vtt.pb(res);
}
sort(rall(vtt));
if(vtt.size()==1) return vtt[0];
return vtt[0]+vtt[1]+L;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
15564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
15564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
14 ms |
6484 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
15564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |