# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
361968 | Sparky_09 | Traffic (IOI10_traffic) | C++17 | 1191 ms | 159032 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "traffic.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
void usaco(string s){
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int MX = 1e6;
const int INF = 2e9 + 1;
int fans = 0;
vector<int> g[MX], nodes(MX), people(MX), children(MX);
void dfs (int v, int parent) {
for (auto x: g[v]) {
if (x == parent) continue;
dfs(x, v);
children[v] += children[x];
people[v] = max(people[v], children[x]);
}
people[v] = max(people[v], fans - children[v] - nodes[v]);
children[v] += nodes[v];
}
int LocateCentre (int n, int p[], int d[], int s[]) {
for (int i = 0; i < n; i++) {
fans += p[i];
nodes[i] = p[i];
}
for (int i = 0; i < n - 1; i++) {
g[s[i]].push_back(d[i]);
g[d[i]].push_back(s[i]);
}
dfs(0, -1);
int sol = INF, res = -1;
for (int i = 0; i < n; i++) {
if (people[i] < sol) {
res = i;
sol = people[i];
}
}
return res;
}
/*
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
}
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |