Submission #278808

# Submission time Handle Problem Language Result Execution time Memory
278808 2020-08-21T23:25:12 Z ec1117 Traffic (IOI10_traffic) C++17
0 / 100
16 ms 23808 KB
#include "bits/stdc++.h"
#include "traffic.h"
using namespace std;

#define pb push_back
#define mp make_pair

typedef vector<int> vi;

vi adj[1000001];
long long sum[1000001];
int pars[1000001];

void dfs(int n, int par){
    pars[n]=par;
    for(int x:adj[n]){
        if(x!=par){
            dfs(x,n);
        }
        sum[n]+=sum[x];
    }
}

int LocateCentre(int n, int p[], int s[], int d[]){//int[] s?
    long long tsum=0;
    for(int i=0;i<n;i++){
        adj[s[i]].push_back(d[i]);
        adj[d[i]].push_back(s[i]);
    }
    for(int i=0;i<n;i++){
        sum[i]=p[i];
    }
    dfs(0,0);
    int ret=0;
    long long mins=LLONG_MAX;
    pars[0]=0;
    for(int i=0;i<n;i++){
        long long tmp=0;
        for(int j:adj[i]){
            if(j!=pars[i]+1) {
                tmp = max(tmp, sum[j]);
            }
        }
        tmp=max(tmp,sum[0]-sum[i]);
        if(tmp<mins){
            mins=tmp;
            ret=i;
        }
    }
    return ret;
}




Compilation message

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:25:15: warning: unused variable 'tsum' [-Wunused-variable]
   25 |     long long tsum=0;
      |               ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -