Submission #30169

#TimeUsernameProblemLanguageResultExecution timeMemory
30169inqrDreaming (IOI13_dreaming)C++14
0 / 100
1071 ms15336 KiB
#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 < int > radius; 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; radius.pb(0); 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); radius.pb(mincw); } 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(radius));int rs=radius.size(); if(rs==1)return ans; if(rs==2){ umax(ans,radius[0]+radius[1]+l);return ans; } for(int i=0;i<rs-1;i++){ umax(ans,radius[i]+radius[rs-1]+l); } umax(ans,radius[rs-2]+radius[rs-3]+2*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++)
              ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...