답안 #345622

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
345622 2021-01-07T16:41:48 Z izhang05 Traffic (IOI10_traffic) C++17
0 / 100
15 ms 23788 KB
#ifndef DEBUG
#include <traffic.h>
#endif

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6 + 5, inf = 2e9;
vector<int> adj[maxn];
int down[maxn], up[maxn], v[maxn], n, con[maxn];

void dfs(int node, int p) {
    for (int i : adj[node]) {
        if (i != p) {
            dfs(i, node);
            int cur = down[i] + v[i];
            down[node] += cur;
            con[node] = max(con[node], cur);
        }
    }
}

int LocateCentre(int cur_n, int cur_p[], int s[], int d[]) {
    n = cur_n;
    for (int i = 0; i < n - 1; ++i) {
        adj[s[i]].push_back(d[i]);
        adj[d[i]].push_back(s[i]);
    }
    for (int i = 0; i < n; ++i) {
        v[i] = cur_p[i];
    }
    dfs(0, -1);
    for (int i = 0; i < n; ++i) {
        con[i] = max(con[i], down[0] - down[i] - v[i]);
    }
    pair<int, int> sol = {inf, 0};
    for (int i = 0; i < n; ++i) {
        sol = min(sol, make_pair(con[i], i));
    }
    return sol.second;
}

#ifdef DEBUG

int main() {
    int n = 5, p[5]{3, 5, 8, 10, 9}, s[4]{0, 1, 2, 3}, d[4]{1, 2, 3, 4};
    cout << LocateCentre(n, p, s, d) << "\n";
}

#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Incorrect 15 ms 23788 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Incorrect 15 ms 23788 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Incorrect 15 ms 23788 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Incorrect 15 ms 23788 KB Output isn't correct
4 Halted 0 ms 0 KB -