Submission #1075648

#TimeUsernameProblemLanguageResultExecution timeMemory
1075648TrumlingDreaming (IOI13_dreaming)C++14
100 / 100
85 ms20108 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define F first #define S second #define enter cout<<'\n'; #define INF 99999999999999999 #define MOD 1000000007 #define all(x) x.begin(),x.end() vector<vector<pair<ll,ll>>>g; vector<bool>vis; vector<ll>dist,par; ll n,m; void dfs1(int start,int pre,ll &maxi) { for(auto x:g[start]) if(x.F!=pre) { par[x.F]=start; vis[x.F]=1; dist[x.F]= dist[start] + x.S; if(dist[maxi]<dist[x.F]) maxi=x.F; dfs1(x.F, start,maxi); } } void dfs2(int start,int pre,ll &ans,ll diff,ll curr,ll count) { for(auto x:g[start]) if(x.F!=pre) dfs2(x.F,start,ans,diff,curr + x.S,count); } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { n=N; m=M; g.assign(n,vector<pair<ll,ll>>()); vis.assign(n,0); dist.assign(n,0); par.assign(n,0); for(int i=0;i<m;i++) { g[A[i]].pb({B[i],T[i]}); g[B[i]].pb({A[i],T[i]}); } vector<ll>ans; ll ansi=-1; ll idx=0; for(int i=0;i<N;i++) if(!vis[i]) { vis[i]=1; ll p1=i,p2; dfs1(i,i,p1); dist[p1]=0; p2=p1; dfs1(p1,p1,p2); ll curr=0; ll diff=INF; ll count=dist[p2]; ansi=max(ansi,dist[p2]); ll curri=0; while(p2!=p1) { if(diff > abs((count-curr)-curr)) { curri=max(curr,count-curr); diff= abs((count-curr)-curr); } curr+=dist[p2]-dist[par[p2]]; p2=par[p2]; } ans.pb(curri); } sort(all(ans)); return max(ansi,max((((ans.size()>=2))?ans[ans.size()-1] + ans[ans.size()-2] + L:0),((ans.size()>=3)?ans[ans.size()-2] + ans[ans.size()-3] + 2*L:0))); }

Compilation message (stderr)

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:60:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   60 |     for(int i=0;i<N;i++)
      |     ^~~
dreaming.cpp:90:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   90 |  sort(all(ans));
      |  ^~~~
dreaming.cpp:59:8: warning: unused variable 'idx' [-Wunused-variable]
   59 |     ll idx=0;
      |        ^~~
#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...