# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378362 | 2021-03-16T14:59:37 Z | Bidrift | Traffic (IOI10_traffic) | C++17 | 0 ms | 0 KB |
#include <iostream> #include <vector> #include <set> #include <cmath> #include <algorithm> #include <cctype> #include <string> #include <fstream> #include <list> #include <map> #include <unordered_map> #include <unordered_set> #include <queue> #include <stack> #include <iomanip> #include "traffic.h" #define pb push_back #define eb emplace_back #define all(a) a.begin(), a.end() #define srt(a) sort(all(a)); #define srtc(a,comp) sort(all(a),comp); #define srtb(a) sort(a.rbegin(),a.rend()); #define boost ios::sync_with_stdio(false); cin.tie(0); cin.tie(0); using ll = long long; using namespace std; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<bool> vb; typedef pair<int,int> ii; typedef vector<ii> vpi; const int dx[4][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}}; //right left down up void setIO(string name = "") { // name is nonempty for USACO file I/O ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output // alternatively, cin.tie(0)->sync_with_stdio(0); freopen((name+".in").c_str(), "r", stdin); // see Input & Output freopen((name+".out").c_str(), "w", stdout); } vi adj[100005], nodes(100005,0), people(100005,0), children(100005, 0); int fans = 0; void DFS(int parent, int avoid){ for (auto x: adj[parent]){ if (x == avoid) continue; DFS(x,parent); children[parent]+= children[x]; people[parent] = max(people[parent],children[x]); } people[parent] = max(people[parent], fans-children[parent]-nodes[parent]); children[parent] += nodes[parent]; } int locateCenter(int n, int p[], int s[], int d[]){ for (int i = 0; i < n; i++){ fans += p[i]; nodes[i] = p[i]; } for (int i = 0; i < n-1; i++){ adj[s[i]].pb(d[i]); adj[d[i]].pb(s[i]); } DFS(0,-1); int ans, mini = INT32_MAX; for (int i = 0; i < n; i++){ if (people[i] < mini){ ans = i; mini = people[i]; } } return ans; }