Submission #1028263

#TimeUsernameProblemLanguageResultExecution timeMemory
1028263TobTraffic (IOI10_traffic)C++14
100 / 100
803 ms159060 KiB
#include <bits/stdc++.h> #include "traffic.h" #define F first #define S second #define all(x) x.begin(), x.end() #define pb push_back #define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; typedef long long ll; typedef pair <ll, ll> pii; const int N = 1e6 + 7; int sum, fo; int a[N], siz[N], res[N]; vector <int> adj[N]; int dfs(int x, bool rev, int p = -1, int d = 0) { if (!rev) { siz[x] = a[x]; for (auto y : adj[x]) if (y != p) siz[x] += dfs(y, 0, x); return siz[x]; } int mx = d, cur = x; for (auto y : adj[x]) if (y != p) mx = max(mx, siz[y]); res[x] = mx; for (auto y : adj[x]) if (y != p) { int z = dfs(y, 1, x, sum-siz[y]); if (res[z] < res[cur]) cur = z; } return cur; } int LocateCentre(int n, int pp[], int S[], int D[]) { for (int i = 0; i < n; i++) { a[i] = pp[i]; sum += a[i]; } for (int i = 0; i < n-1; i++) { adj[S[i]].pb(D[i]); adj[D[i]].pb(S[i]); } dfs(0, 0); return dfs(0, 1); } //----------------------------------------- /* static int NN,PP[1000000],SS[1000000],DD[1000000]; int main(){ int i; scanf("%d",&NN); for (i=0;i<NN;i++) scanf("%d",&PP[i]); for (i=0;i<NN-1;i++) scanf("%d%d",&SS[i],&DD[i]); int r = LocateCentre(NN,PP,SS,DD); printf("%d\n",r); return 0; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...