#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 vis[li],mn,M[li],M2[li],node[li],ss;
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){
int t,x,xx,xxx;
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]));
}
x=-inf,xx=-inf,xxx=-inf;
for(int i=0;i<n;i++){
if(vis[i]==1) continue;
mn=1e9;
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));
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:45:6: warning: unused variable 't' [-Wunused-variable]
int t,x,xx,xxx;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
12024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
12024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
12024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
6460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
12024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
12024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |