Submission #233526

# Submission time Handle Problem Language Result Execution time Memory
233526 2020-05-20T20:00:02 Z ant101 Traffic (IOI10_traffic) C++14
0 / 100
7 ms 5076 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 P[], 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;
}

Compilation message

traffic.cpp:63:36: warning: 'D' defined but not used [-Wunused-variable]
 static int N,P[1000000],S[1000000],D[1000000];
                                    ^
traffic.cpp:63:25: warning: 'S' defined but not used [-Wunused-variable]
 static int N,P[1000000],S[1000000],D[1000000];
                         ^
traffic.cpp:63:12: warning: 'N' defined but not used [-Wunused-variable]
 static int N,P[1000000],S[1000000],D[1000000];
            ^
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -