Submission #218914

#TimeUsernameProblemLanguageResultExecution timeMemory
218914KoalaMuchDreaming (IOI13_dreaming)C++14
0 / 100
58 ms11768 KiB
#include "dreaming.h" //#include "grader.cpp" #include<bits/stdc++.h> using namespace std; const int MxN = 1e5+5; vector< pair< int,int > > g[MxN]; bool mark[MxN]; int ans; int dp[MxN][2]; int all[MxN]; void dfs(int u,int p = -1) { mark[u] = 1; for(auto &x:g[u]) { if(x.first==p) continue; dfs(x.first,u); if(dp[x.first][0]+x.second>dp[u][0]) dp[u][0] = dp[x.first][0]+x.second; else if(dp[x.first][0]+x.second>dp[u][1]) dp[u][1] = dp[x.first][0]+x.second; } } int reroot(int u,int p = -1) { int mn = 2e9; for(auto &x:g[u]) { if(x.first==p) continue; int nowv = x.second+dp[x.first][0]; if(nowv==dp[u][0]) nowv = dp[u][1]+x.second; if(nowv>dp[x.first][0]) dp[x.first][0] = nowv; else if(nowv>dp[x.first][1]) dp[x.first][1] = nowv; mn = min(mn,reroot(x.first,u)); } ans = max(ans,dp[u][0]+dp[u][1]); return min(mn,dp[u][0]); } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { int n = 0; for(int i=0;i<M;i++) g[A[i]].push_back({B[i],T[i]}),g[B[i]].push_back({A[i],T[i]}); for(int i=0;i<N;i++) { if(!mark[i]) { ++n; dfs(i); all[n] = reroot(i); } } sort(all+1,all+n+1); if(n>=2) ans = max(ans,all[1]+all[2]+L); if(n>=3) ans = max(ans,all[2]+all[3]+2*L); return ans; }
#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...