Submission #1033533

#TimeUsernameProblemLanguageResultExecution timeMemory
1033533ezzzayDreaming (IOI13_dreaming)C++14
0 / 100
14 ms3664 KiB
#include "dreaming.h" #include<bits/stdc++.h> using namespace std; #define pb push_back #define ff first #define ss second const int MN=4000; vector<pair<int,int>>v[MN]; bool vis[MN]; int dist[MN]; vector<int>tmp; void df(int a){ vis[a]=1; tmp.pb(a); for(auto p:v[a]){ if(vis[p.ff]==0)df(p.ff); } } vector<int>vh; int z=0; void dfs(int a, int u){ for(auto p:v[a]){ int b=p.ff; int c=p.ss; if(b==u)continue; dist[b]=dist[a]+c; z=max(z,dist[b]); dfs(b,a); } } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { memset(vis,0,sizeof vis); for(int i=0;i<M;i++){ v[A[i]].pb({B[i],T[i]}); v[B[i]].pb({A[i],T[i]}); } vector<int>vec; for(int i=0;i<N;i++){ if(vis[i]==0){ tmp.clear(); df(i); int g=1e9; for(auto a:tmp){ memset(dist,0,sizeof dist); vh.clear(); z=0; dfs(a,-1); g=min(g,z); } vec.pb(g); } } sort(vec.begin(),vec.end(),greater<int>()); if(vec.size()==2){ return vec[0]+vec[1]+L; } else{ return max(vec[0]+vec[1]+L,vec[1]+vec[2]+L*2); } }
#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...