#include "dreaming.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define lo long long
#define inf 1000000009
#define md 1000000007
#define li 100005
#define mp make_pair
#define pb push_back
using namespace std;
int x=-inf,xx=-inf,xxx=-inf,vis[li],mn,M[li],M2[li],node[li],ss,m;
vector< pair<int,int> > v[li];
void f(int x){
vis[x]=1;
int t;
for(int i=0;i<(int)v[x].size();i++){
int go=v[x][i].fi;
int knr=v[x][i].se;
if(vis[go]==1) continue;
f(go);
t=M[go]+knr;
if(M[x]<t){
M2[x]=M[x];
M[x]=t;
node[x]=go;
}
else if(M2[x]<t){
M2[x]=t;
}
}
ss=max(ss,M[x]+M2[x]);
}
void g(int x,int p,int t){
mn=min(mn,max(M[x],t));
for(int i=0;i<(int)v[x].size();i++){
int go=v[x][i].fi;
int knr=v[x][i].se;
if(go==p) continue;
int a=max(t,node[x]==go?M2[x]:M[x]);
g(go,x,a+knr);
}
}
int travelTime(int n,int m,int l,int *A,int *B,int *T){
for(int i=0;i<m;i++){
v[A[i]].pb(mp(B[i],T[i]));
v[B[i]].pb(mp(A[i],T[i]));
}
for(int i=0;i<n;i++){
if(vis[i]==1) continue;
mn=inf;
f(i);
g(i,-1,0);
if(x<mn){
x=mn;
xx=x;
xxx=xx;
}
else if(xx<mn){
xx=mn;
xxx=xx;
}
else if(xxx<mn){
xxx=mn;
}
}
return max(ss,max(x+xx+l,xx+xxx+l+l));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
12024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
12024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
12024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
6648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
12024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
12024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |