Submission #233527

# Submission time Handle Problem Language Result Execution time Memory
233527 2020-05-20T20:01:00 Z ant101 Traffic (IOI10_traffic) C++14
Compilation error
0 ms 0 KB
#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 pp[], 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;
}


int main(){
    int i;
    scanf("%d",&N);
    for (i=0;i<N;i++) scanf("%d",&P[i]);
    for (i=0;i<N-1;i++) scanf("%d%d",&S[i],&D[i]);
    int r = LocateCentre(N,P,S,D);
    printf("%d\n",r);
    return 0;
}

Compilation message

traffic.cpp: In function 'int main()':
traffic.cpp:114:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
traffic.cpp:115:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i=0;i<N;i++) scanf("%d",&P[i]);
                       ~~~~~^~~~~~~~~~~~
traffic.cpp:116:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i=0;i<N-1;i++) scanf("%d%d",&S[i],&D[i]);
                         ~~~~~^~~~~~~~~~~~~~~~~~~~
/tmp/cchiwmb6.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc6o4GwG.o:traffic.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status