(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #317048

#TimeUsernameProblemLanguageResultExecution timeMemory
317048nandonathanielTraffic (IOI10_traffic)C++14
100 / 100
1299 ms151644 KiB
#include "traffic.h" #include <bits/stdc++.h> using namespace std; const int MAXN=1e6+5; vector<int> adj[MAXN]; int subtree[MAXN],atas[MAXN]; void dfs(int now,int par){ atas[now]=par; for(auto nxt : adj[now]){ if(nxt==par)continue; dfs(nxt,now); subtree[now]+=subtree[nxt]; } } int LocateCentre(int N, int P[], int S[], int D[]) { for(int i=0;i<N;i++)subtree[i]=P[i]; for(int i=0;i<N-1;i++){ adj[S[i]].push_back(D[i]); adj[D[i]].push_back(S[i]); } dfs(0,-1); int ans=INT_MAX,idx; for(int i=0;i<N;i++){ int ret=0; for(auto j : adj[i]){ if(j==atas[i])ret=max(ret,subtree[0]-subtree[i]); else ret=max(ret,subtree[j]); } // cout << i << " " << ret << '\n'; if(ret<ans){ ans=ret; idx=i; } } return idx; } //int main(){ // int N; // cin >> N; // int P[N],S[N-1],D[N-1]; // for(int i=0;i<N;i++)cin >> P[i]; // for(int i=0;i<N-1;i++)cin >> S[i] >> D[i]; // cout << LocateCentre(N,P,S,D) << '\n'; // return 0; //}

Compilation message (stderr)

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:38:9: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |  return idx;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...