이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "traffic.h"
#define ll long long int
#define pb push_back
#define mp make_pair
#define FOR(i,n) for(i=0;i<(n);++i)
#define FORe(i,n) for(i=1;i<=(n);++i)
#define FORr(i,a,b) for(i=(a);i<(b);++i)
#define FORrev(i,n) for(i=(n);i>=0;--i)
#define F0R(i,n) for(int i=0;i<(n);++i)
#define F0Re(i,n) for(int i=1;i<=(n);++i)
#define F0Rr(i,a,b) for(ll i=(a);i<(b);++i)
#define F0Rrev(i,n) for(int i=(n);i>=0;--i)
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define ff first
#define ss second
#define cd complex<double>
#define vcd vector<cd>
#define ldd long double
#define dbgLine cout<<"Line : "<<__LINE__<<'\n'
#define all(x) (x).begin(),(x).end()
using namespace std;
/*
const short int __PRECISION = 10;
const ll MOD = 1e9+7;
const ll INF = 1e17 + 1101;
const ll LOGN = 17;
const ll MAXN = 1e6+5;
const ll ROOTN = 320;
const ldd PI = acos(-1);
const ldd EPS = 1e-7;*/
#define MAXN 1000006
#define INF 1000000000000017
vector<ll> g[MAXN];
ll People[MAXN], dp[MAXN], sum[MAXN], sm;
ll dfs(ll a, ll par)
{
dp[a] = 0;
sum[a] = People[a];
for(ll b : g[a])
if(b != par)
dp[a] = max(dp[a], dfs(b, a)), sum[a] += sum[b];
return sum[a];
}
int LocateCentre(int N, int* P, int* S, int* D)
{
sm = 0;
F0R(i, N)
g[i].clear(), People[i] = P[i], sm += P[i];
F0R(i, N-1)
{
g[S[i]].pb(D[i]);
g[D[i]].pb(S[i]);
}
dfs(0, -1);
ii mx = mp(INF, 0);
F0R(i, N)
mx = min(mx, mp(max(dp[i],sm - sum[i]),(ll) i));
//cerr<<mx.ff<<' '<<mx.ss<<'\n';
return mx.ss;
}
/*
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin>>N;
int P[N], S[N], D[N];
F0R(i, N)
cin>>P[i];
F0R(i, N-1)
cin>>S[i]>>D[i];
cout<<LocateCentre(N, P, S, D);
return 0;
}*/
# | 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... |