제출 #1365815

#제출 시각아이디문제언어결과실행 시간메모리
1365815lrnnzTraffic (IOI10_traffic)C++20
100 / 100
483 ms145224 KiB
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define ll long long
#define ld long double
#define ui __int128_t
#define pb push_back
#define fi first
#define se second

const ll MOD3 = 1e9 + 7;
const ll MOD = 998244353;
const ll MOD2 = 676767677;
const ll inf = 1e18;
const ll infs = 1e12;

/********* DEBUG *********/

template<typename T>
struct is_vector : false_type {};

template<typename T, typename A>
struct is_vector<vector<T, A>> : true_type {};

template<typename T>
void print_one(const T& x) {
    if constexpr (is_vector<T>::value) {
        for (size_t i = 0; i < x.size(); i++) {
            cout << x[i];
            if (i + 1 < x.size()) cout << ' ';
        }
    } else {
        cout << x;
    }
}

template<typename... Args>
void out(const Args&... args) {
    bool first = true;

    auto print_arg = [&](const auto& v) {
        if (!first) cout << ' ';
        first = false;
        print_one(v);
    };

    (print_arg(args), ...);
    cout << endl;
}

/********* DEBUG *********/


/********* TEMPS *********/

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

static inline ll splix(ll x) {
    x += 0x9e3779b97f4a7c15ULL;
    ll z = x;
    z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
    z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
    return z ^ (z >> 31);
}

/********* TEMPS *********/

#include "traffic.h"
int LocateCentre(int N, int pp[], int S[], int D[]) {
    vector<vector<ll>> adj(N);
    for (int i = 0; i < N-1; i++) {
        adj[S[i]].pb(D[i]);
        adj[D[i]].pb(S[i]);
    }

    vector<ll> cost(N);
    auto dfs = [&](auto &&dfs, ll u, ll p) -> void {
        cost[u] = pp[u];
        for (auto &v : adj[u]) {
            if (v == p) continue;
            dfs(dfs, v, u);
            cost[u] += cost[v];
        }
    }; dfs(dfs, 0, 0);

    ll ans = 0, mn = inf;
    auto dp = [&](auto &&dp, ll u, ll p) -> void {
        ll cur = 0, sum = 0;
        for (auto &v : adj[u]) {
            chmax(cur, cost[v]);
            sum += cost[v];
        }

        if (chmin(mn, cur))
            ans = u;
        
        for (auto &v : adj[u]) {
            if (v == p) continue;
            ll oc = cost[u];
            cost[u] = sum - cost[v] + pp[u];
            cost[v] -= pp[v];

            dp(dp, v, u);

            cost[u] = oc;
            cost[v] += pp[v];
        }
    }; dp(dp, 0, 0);

    return ans;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…