Submission #286815

#TimeUsernameProblemLanguageResultExecution timeMemory
286815TMJNDreaming (IOI13_dreaming)C++17
100 / 100
115 ms16604 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; struct edge{ int to,dist; }; bool vis[100000]; int D[100000],DD[100000],DDD[100000],res; vector<edge>E[100000]; void dfs0(int x,int from,vector<int>&v){ vis[x]=true; v.push_back(x); for(edge e:E[x]){ if(e.to==from)continue; D[e.to]=D[x]+e.dist; dfs0(e.to,x,v); } } void dfs1(int x,int from){ for(edge e:E[x]){ if(e.to==from)continue; DD[e.to]=DD[x]+e.dist; dfs1(e.to,x); } } void dfs2(int x,int from){ for(edge e:E[x]){ if(e.to==from)continue; DDD[e.to]=DDD[x]+e.dist; dfs2(e.to,x); } } int travelTime(int N, int M, int L, int a[], int b[], int d[]) { for(int i=0;i<M;i++){ E[a[i]].push_back({b[i],d[i]}); E[b[i]].push_back({a[i],d[i]}); } vector<int>v; for(int i=0;i<N;i++){ if(!vis[i]){ vector<int>V; dfs0(i,i,V); pair<int,int>p={-1,-1}; for(int j:V){ p=max(p,{D[j],j}); } dfs1(p.second,p.second); pair<int,int>pp={-1,-1}; for(int j:V){ pp=max(pp,{DD[j],j}); } dfs2(pp.second,pp.second); int mn=2000000000; for(int j:V){ mn=min(mn,max(DD[j],DDD[j])); } res=max(res,pp.first); v.push_back(mn); } } sort(v.begin(),v.end(),greater<>()); if(v.size()==1){ return res; } else if(v.size()==2){ return max(res,v[0]+v[1]+L); } else{ return max({res,v[0]+v[1]+L,v[1]+v[2]+L+L}); } }
#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...