Submission #1022009

#TimeUsernameProblemLanguageResultExecution timeMemory
1022009amine_arouaDreaming (IOI13_dreaming)C++17
47 / 100
823 ms65536 KiB
#include "dreaming.h" #include<bits/stdc++.h> using namespace std; vector<vector<pair<int ,int>>> adj; vector<int> center; vector<bool> vis; int mx = 0; int y = 0; int z = 0; void dfs1(int x , int p = -1 , int d = 0) { vis[x] = 1; if(mx <= d) { mx = d; y = x; } for(auto [u , c] : adj[x]) { if(u == p) continue; dfs1(u , x , d + c); } } vector<pair<int ,int>> par; void dfs2(int x , int p = -1 , int d = 0) { if(mx <= d) { mx = d; z = x; } for(auto [u , c] : adj[x]) { if(u == p) continue; par[u]= {x , c}; dfs2(u , x , d + c); } } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { adj.assign(N , {}); vis.assign(N , 0); for(int i = 0 ; i < M; i++) { adj[A[i]].push_back({B[i] , T[i]}); adj[B[i]].push_back({A[i] , T[i]}); } par.assign(N , {-1 , -1}); for(int i = 0 ; i < N ; i++) { if(!vis[i]) { y = 0; mx = 0; dfs1(i); mx = 0; z = 0; dfs2(y); int sm = 0; int mid = z; int mn = mx; while(par[z].first != -1) { sm += par[z].second; if(abs(mx - 2*sm) <= mn) { mid = par[z].first; mn = abs(mx - 2*sm); } z = par[z].first; } center.push_back(mid); } } int ans = 0; for(int i = 0 ; i < (int)center.size() ; i++) { auto oadj = adj; for(int j = 0 ; j < (int)center.size() ; j++) { if(i == j) continue; adj[center[i]].push_back({center[j] ,L}); adj[center[j]].push_back({center[i] , L}); } y = 0; mx = 0; vis.assign(N , 0); dfs1(0); mx = 0; z = 0; dfs2(y); ans = max(ans , mx); adj = oadj; } 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...