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 int ll
//#define endl '\n'
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define re resize
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
#define print(x) cout << #x << ": " << x << endl
typedef long long ll;
typedef vector<int> vi;
typedef array<ll, 2> ii;
typedef array<int, 3> ti;
typedef vector<ii> vii;
typedef vector<ti> vti;
typedef priority_queue<int> pq;
template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }
const ll inf = 1e17;
const int maxn = 1e6;
vi adj[maxn];
ll sub[maxn];
ll c_sub[maxn];
ll c_par[maxn];
int LocateCentre(int n, int pp[], int s[], int d[]) {
loop(i, n-1) {
adj[s[i]].pb(d[i]);
adj[d[i]].pb(s[i]);
}
auto dfs = [&](int u, int p, auto&& dfs) -> void {
c_sub[u] = 0;
sub[u] = pp[u];
for (int v : adj[u]) if (v != p) {
dfs(v, u, dfs);
c_sub[u] -= c_sub[v] + sub[v];
sub[u] -= sub[v];
sub[v] += sub[u];
c_sub[v] += c_sub[u] + sub[u];
}
};
dfs(0, 0, dfs);
auto moveroot = [&](int u, int v) -> void {
c_sub[v] += c_sub[u] + sub[v];
};
auto dfs3 = [&](int u, int p, auto&& dfs3) -> ii {
ii res = {c_sub[u], u};
for (int v : adj[u]) if (v != p) {
moveroot(u, v);
ckmin(res, dfs3(v, u, dfs3));
moveroot(v, u);
}
return res;
};
return dfs3(0, 0, dfs3)[1];
}
# | 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... |