Submission #286809

#TimeUsernameProblemLanguageResultExecution timeMemory
286809TMJNDreaming (IOI13_dreaming)C++17
18 / 100
53 ms11132 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; struct edge{ int to,dist; }; bool vis[100000]; int D[100000]; vector<edge>E[100000]; void dfs(int x,int from){ vis[x]=true; for(edge e:E[x]){ if(e.to==from)continue; dfs(e.to,x); D[x]=max(D[x],D[e.to]+e.dist); } } 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]){ dfs(i,i); int p=i; int from=i; int m=0; int mn=D[i]; while(true){ pair<int,int>mx={-1,-1}; for(edge e:E[p]){ if(e.to==from)continue; mx=max(mx,{D[e.to]+e.dist,e.to}); } if(mx==pair<int,int>{-1,-1})break; for(edge e:E[p]){ if(e.to==from||e.to==mx.second)continue; m=max(m,D[e.to]+e.dist); } mn=min(mn,max(m,D[p])); for(edge e:E[p]){ if(e.to==mx.second)m+=e.dist; } from=p; p=mx.second; } v.push_back(mn); } } sort(v.begin(),v.end(),greater<>()); if(v.size()==1){ return v.front(); } else if(v.size()==2){ return v[0]+v[1]+L; } else{ return max(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...