This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dreaming.h"
#include <vector>
#include <stdio.h>
using namespace std;
vector < pair < int , int > > Next[100005];
bool have[100005]={0};
int a=-1e8,b=-1e8,c=-1e8,t=0,big=0,bb=0,where;
void F(int here,int con)
{
if(con>=big)
{
big=con;
where=here;
}
have[here]=1;
for(auto i:Next[here]) if(!have[i.first]) F(i.first,con+i.second);
}
void F2(int here,int Father,int con)
{
t=min(t,max(con,big-con));
for(auto i:Next[here]) if(i.first!=Father) F2(i.first,here,con+i.second);
}
void F3(int here,int Father,int con)
{
big=max(big,con);
for(auto i:Next[here]) if(i.first!=Father) F3(i.first,here,con+i.second);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
int i;
for(i=0;i<M;i++)
{
Next[A[i]].push_back(make_pair(B[i],T[i]));
Next[B[i]].push_back(make_pair(A[i],T[i]));
}
for(i=0;i<N;i++)
{
if(!have[i])
{
big=0;
where=0;
F(i,0);
F3(where,-1,0);
bb=max(bb,big);
t=1e9;
F2(where,-1,0);
//printf("aa %d %d\n",i,t);
if(t>=a)
{
c=b;
b=a;
a=t;
}
else if(t>=b)
{
c=b;
b=t;
}
else if(t>=c) c=t;
}
}
//printf("%d %d %d %d\n",bb,a,b,c);
return max(max(bb,a+b+L),b+c+2*L);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |