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 ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
const int mxn=1e6+5;
int a[mxn],b[mxn];
vector<int>vt[mxn];
int dfs(int u,int p,int arr[]){
int ans=0;
for(int v:vt[u]){
if(v!=p){
ans=max(ans,dfs(v,u,arr));
}
}
return ans+arr[u];
}
int LocateCentre(int n, int arr[], int S[], int D[]) {
bool q=true;
for(int i=0;i<n-1;i++){
if(S[i]!=i||D[i]!=i+1){
q=false;
}
}
if(q){
a[0]=arr[0];
for(int i=1;i<n;i++){
a[i]=a[i-1]+arr[i];
}
b[n-1]=arr[n-1];
for(int i=n-2;i>=0;i--){
b[i]=b[i+1]+arr[i];
}
int ans=2000000000,k=0;
for(int i=0;i<n;i++){
int x=0;
if(i-1>=0){
x=a[i-1];
//cout<<a[i-1]<<' ';
}
if(i+1<n){
x=max(x,b[i+1]);
//cout<<b[i+1]<<' ';
}
//cout<<endl;
//cout<<x<<' ';
if(x<ans){
k=i;
ans=x;
}
}
return k;
}
for(int i=0;i<n-1;i++){
vt[S[i]].pb(D[i]);
vt[D[i]].pb(S[i]);
}
ll maxs=INF,kk=0;
for(int i=0;i<n;i++){
int sum=dfs(i,-1,arr)-arr[i];
if(sum<maxs){
maxs=sum;
kk=i;
}
}
return kk;
}
# | 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... |