Submission #788024

#TimeUsernameProblemLanguageResultExecution timeMemory
788024allin27x꿈 (IOI13_dreaming)C++17
100 / 100
191 ms49056 KiB
#include <bits/stdc++.h> using namespace std; #include "dreaming.h" #define int long long int ds[2][(int)1e5]; unordered_map<int,int> adj[(int)1e5]; int vis[(int)1e5]; int ind = 0; unordered_set<int> sets[(int)1e5]; int cp[(int)1e5]; void dfs(int i , int p, int len, int x){ sets[ind].insert(i); vis[i] = 1; ds[x][i] = len; for (auto const &pair: adj[i]){ int c = pair.first; int w= pair.second; if (c==p) continue; dfs(c,i, len+w,x); } } signed travelTime(signed N, signed M, signed L, signed A[], signed B[], signed T[]){ for (int i=0; i<M; i++){ int a = A[i]; int b = B[i]; adj[a][b] = T[i]; adj[b][a] = T[i]; } int ans1 = 0 ; for (int i=0; i<N; i++) vis[i] = 0; for (int i=0; i<N; i++){ if (vis[i]) continue; dfs(i,i,0,0); int a1 = i; for (auto c: sets[ind]){ if (ds[0][c]>ds[0][a1]) a1 = c; } dfs(a1,a1,0,0); int a2 = a1; for (auto c: sets[ind]){ if (ds[0][c]>ds[0][a2]) a2 = c; } dfs(a2,a2,0,1); int ans = 1e7; for (auto c: sets[ind]){ ans = min(ans, max(ds[0][c], ds[1][c])); } ans1 = max(ans1, ds[1][a1]); cp[ind] = ans; ind++; } if (ind == 1){ return ans1; } sort(cp, cp+ind); if (ind == 2) return max(ans1, L + cp[ind-1] + cp[ind-2]); return max(ans1, max(L + cp[ind-1] + cp[ind-2], 2*L + cp[ind-2] + cp[ind-3])); } // signed main(){ // signed n = 10, m = 8 ; // signed l = 2; // signed a[] = {1, 2, 3, 4, 5, 6, 7, 8}; // signed b[] = {2, 3, 4, 5, 6, 7, 8, 9}; // signed t[] = {4, 2, 4, 3, 7, 1, 5, 3}; // cout<<travelTime(n,m,l,a,b,t); // }
#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...