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 <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;
//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007
typedef long long ll;
ll add(ll a, ll b) {
a += b;
if(a >= MOD) {
a -= MOD;
}
return a;
}
ll sub(ll a, ll b) {
a -= b;
if(a < 0) {
a += MOD;
}
return a;
}
ll mul(ll a, ll b) {
return (a * b)%MOD;
}
void add_self(ll& a, ll b) {
a = add(a, b);
}
void sub_self(ll& a, ll b) {
a = sub(a, b);
}
void mul_self(ll& a, ll b) {
a = mul(a, b);
}
const ll MAXN = 200010;
static int N,P[1000000],S[1000000],D[1000000];
vector<ll> adj[MAXN];
ll sz[MAXN];
pair<ll, ll> best = {1e13, -1};
int LocateCentre(int N, int P[], int S[], int D[]);
ll dfs(ll u, ll p) {
sz[u] = P[u];
for (auto v : adj[u]) {
if (v != p) {
sz[u]+=dfs(v, u);
}
}
return sz[u];
}
void dfs2(ll u, ll p) {
ll hc = -1;
for (auto v : adj[u]) {
hc = max(hc, sz[v]);
}
best = min(best, {hc, u});
for (auto v : adj[u]) {
if (v != p) {
ll o1 = sz[u], o2 = sz[v];
sz[u]-=sz[v];
sz[v] = o1;
dfs2(v, u);
sz[u] = o1;
sz[v] = o2;
}
}
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
memcpy(P, pp, sizeof(*pp));
for (ll i = 0; i<N-1; i++) {
adj[S[i]].push_back(D[i]);
adj[D[i]].push_back(S[i]);
}
dfs(0, -1);
dfs2(0, -1);
return best.second;
}
Compilation message (stderr)
traffic.cpp:63:36: warning: 'D' defined but not used [-Wunused-variable]
static int N,P[1000000],S[1000000],D[1000000];
^
traffic.cpp:63:25: warning: 'S' defined but not used [-Wunused-variable]
static int N,P[1000000],S[1000000],D[1000000];
^
traffic.cpp:63:12: warning: 'N' defined but not used [-Wunused-variable]
static int N,P[1000000],S[1000000],D[1000000];
^
# | 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... |