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 <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rt insert
#define st first
#define nd second
#define ll long long
#define pii pair < int , int >
#define DB printf("debug\n");
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define all(x) x.begin() , x.end()
using namespace std;
int n,m,l,ans=-1;
vector < pair < int , int > > ed[150005];
bool in_for[150005];
vector < pair < int , int > > cen;
int maxw,maxwv,dia1,dia2,mincw,mincwv;
vector < int > d1,d2;
void dfs(int vn,int vb,int wn,vector<int>&d){
//printf(" 1:vn=%d vb=%d wn=%d\n",vn,vb,wn);
if(wn>maxw){
maxw=wn;
maxwv=vn;
}
in_for[vn]=1;
d[vn]=wn;
if(d1[vn]!=1e9&&d2[vn]!=1e9&&max(d1[vn],d2[vn])<mincw){
mincw=max(d1[vn],d2[vn]);
mincwv=vn;
}
for(int i=0;i<ed[vn].size();i++)
if(ed[vn][i].st!=vb)
dfs(ed[vn][i].st,vn,wn+ed[vn][i].nd,d);
}
void for_fn(int rt){
d1=d2=vector < int >(150005,1e9);
maxw=maxwv=dia1=dia2=mincwv=-1;mincw=1e9;
//printf("1:rt=%d\n",rt);
if(ed[rt].size()==0){
in_for[rt]=1;
cen.pb(mp(0,rt));
return;
}
dfs(rt,-1,0,d1);
dia1=maxwv;maxw=-1;
ans=max(ans,maxw);
//printf("2:dia1=%d\n",dia1);
dfs(dia1,-1,0,d1);
dia2=maxwv;maxw=-1;
//printf("2:dia2=%d\n",dia2);
dfs(dia2,-1,0,d2);
//printf("rt=%d mincw=%d mincwv=%d\n",rt,mincw,mincwv);
cen.pb(mp(mincw,mincwv));
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
n=N,m=M,l=L;
for(int i=0;i<M;i++){
ed[A[i]].pb(mp(B[i],T[i]));
ed[B[i]].pb(mp(A[i],T[i]));
}
for(int i=0;i<N;i++){
if(!in_for[i])for_fn(i);
}
sort(all(cen));
for(int i=0;i<cen.size()-1;i++){
ans=max(ans,cen[cen.size()-1].st+cen[i].st+l);
}
return ans;
}
Compilation message (stderr)
dreaming.cpp: In function 'void dfs(int, int, int, std::vector<int>&)':
dreaming.cpp:34:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<ed[vn].size();i++)
~^~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:74:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<cen.size()-1;i++){
~^~~~~~~~~~~~~
# | 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... |