This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
//#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
//#include "memory.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
vector <int> x[(int)1e6 + 2]; bool visa[(int)1e6 + 2];
ll ans[(int)1e6 + 2], p[(int)1e6 + 1];
ll all;
int SAAD(int idx , int from) {
visa[idx] = false;
ll sum = 0,a;
for (int i = 0; i < x[idx].size(); i++)
{
if (visa[x[idx][i]]) {
a = SAAD(x[idx][i],idx);
sum += a;
ans[idx] = max(ans[idx],a);
}
}
sum += p[idx];
if (from == -1) return sum;
ans[idx] = max(ans[idx],all-sum);
return sum ;
}
int LocateCentre(int N, int P[], int S[], int D[]) {
memset(visa, 1, sizeof(visa));
for (int i = 0; i < N-1; i++) {
x[S[i]].pb(D[i]);
x[D[i]].pb(S[i]);
}
for (int i = 0; i < N; i++)
{
all += P[i];
p[i] = P[i];
}
SAAD(0,-1);
ll mn = 2e9 , res;
for ( int i = 0; i < N; i++)
{
if ( mn > ans[i] ) {
mn = ans[i];
res = i;
}
}
return res;
}
Compilation message (stderr)
traffic.cpp: In function 'int SAAD(int, int)':
traffic.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i = 0; i < x[idx].size(); i++)
| ~~^~~~~~~~~~~~~~~
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:67:12: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
67 | return res;
| ^~~
# | 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... |