제출 #1028239

#제출 시각아이디문제언어결과실행 시간메모리
1028239TobTraffic (IOI10_traffic)C++14
0 / 100
10 ms23896 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; int a[N], siz[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) continue; siz[x] += dfs(y, 0, x); } return siz[x]; } else { int mx = d; for (auto y : adj[x]) if (y != p) mx = max(mx, siz[y]); int mn = mx; for (auto y : adj[x]) if (y != p) mn = min(mn, dfs(y, 1, x, sum-siz[y])); return mn; } } int LocateCentre(int n, int pp[], int S[], int D[]) { for (int i = 0; i < n; i++) a[i] = pp[i], sum += pp[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...