Submission #557388

#TimeUsernameProblemLanguageResultExecution timeMemory
557388Jarif_RahmanDreaming (IOI13_dreaming)C++17
18 / 100
39 ms11852 KiB
#include "dreaming.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; vector<vector<pair<int, int>>> v; vector<bool> bl; vector<int> dis; void dfs1(int nd, int ss){ bl[nd] = 1; for(auto [x, w]: v[nd]) if(x != ss) dfs1(x, nd); for(auto [x, w]: v[nd]) if(x != ss) dis[nd] = max(dis[nd], dis[x]+w); } int dfs2(int nd, int ss, int s = 0){ int mx = s, smx = s; int rt = s; for(auto [x, w]: v[nd]) if(x != ss){ rt = max(rt, dis[x]+w); if(dis[x]+w > mx) smx = mx, mx = dis[x]+w; else if(dis[x]+w > smx) smx = dis[x]+w; } for(auto [x, w]: v[nd]) if(x != ss) rt = min(rt, dfs2(x, nd, (dis[x]+w == mx?smx:mx)+w)); return rt; } int travelTime(int n, int m, int L, int A[], int B[], int T[]){ v.assign(n, {}); bl.assign(n, 0); dis.assign(n, 0); 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> sth; for(int i = 0; i < n; i++){ if(bl[i]) continue; dfs1(i, -1); sth.pb(dfs2(i, -1)); } sort(sth.rbegin(), sth.rend()); if(sth.size() == 1) return sth[0]; int ans = sth[0]+sth[1]+L; if(sth.size() > 2) ans = max(ans, sth[1]+sth[2]+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...