Submission #764276

# Submission time Handle Problem Language Result Execution time Memory
764276 2023-06-23T09:52:30 Z Blagoj Traffic (IOI10_traffic) C++17
50 / 100
371 ms 126528 KB
#include <bits/stdc++.h>
#include "traffic.h"

#pragma GCC optimize("Ofast,unroll-loops")

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()

vector<int> g[1000003];
int sz[1000003], ppl[1000003];
bool visited[1000003];

void dfs(int n, int p = -1) {
    sz[n] = ppl[n];
    for (auto x : g[n]) {
        if (x == p) continue;
        dfs(x, n);
        sz[n] += sz[x];
    }
}

int LocateCentre(int N, int pp[], int S[], int D[]) {
    for (int i = 0; i < N - 1; i++) g[S[i]].push_back(D[i]);
    for (int i = 0; i < N; i++) ppl[i] = pp[i];
    dfs(0);
    queue<pair<int, int>> q;
    q.push({0, 0});
    visited[0] = 1;
    ll best = LLONG_MAX, id = 0;
    while (q.size() > 0) {
        int place = q.front().first, sum = q.front().second, cnt = 0, mx = q.front().second;
        q.pop();
        for (auto x : g[place]) {
            if (visited[x]) continue;
            mx = max(mx, sz[x]);
            cnt += sz[x];
        }
        if (mx < best) {
            best = mx;
            id = place;
        }
        for (auto x : g[place]) {
            if (visited[x]) continue;
            visited[x] = 1;
            q.push({x, pp[place] + sum + cnt - sz[x]});
        } 
    }
    return id;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23716 KB Output is correct
2 Correct 14 ms 23760 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23800 KB Output is correct
7 Correct 14 ms 23764 KB Output is correct
8 Correct 12 ms 23744 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 14 ms 23820 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 12 ms 23816 KB Output is correct
16 Correct 13 ms 23764 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 11 ms 23764 KB Output is correct
20 Correct 11 ms 23732 KB Output is correct
21 Correct 12 ms 23772 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 14 ms 23792 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 21 ms 23892 KB Output is correct
26 Correct 15 ms 23772 KB Output is correct
27 Correct 12 ms 23812 KB Output is correct
28 Correct 15 ms 23808 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 12 ms 23808 KB Output is correct
31 Correct 12 ms 23860 KB Output is correct
32 Correct 12 ms 23892 KB Output is correct
33 Correct 12 ms 23764 KB Output is correct
34 Correct 11 ms 23768 KB Output is correct
35 Correct 11 ms 23808 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 12 ms 23828 KB Output is correct
38 Correct 13 ms 23812 KB Output is correct
39 Correct 13 ms 23816 KB Output is correct
40 Correct 13 ms 23892 KB Output is correct
41 Correct 12 ms 23892 KB Output is correct
42 Correct 12 ms 23892 KB Output is correct
43 Correct 11 ms 23804 KB Output is correct
44 Correct 12 ms 23728 KB Output is correct
45 Correct 11 ms 23764 KB Output is correct
46 Correct 11 ms 23764 KB Output is correct
47 Correct 12 ms 23744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23716 KB Output is correct
2 Correct 14 ms 23760 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23800 KB Output is correct
7 Correct 14 ms 23764 KB Output is correct
8 Correct 12 ms 23744 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 14 ms 23820 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 12 ms 23816 KB Output is correct
16 Correct 13 ms 23764 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 11 ms 23764 KB Output is correct
20 Correct 11 ms 23732 KB Output is correct
21 Correct 12 ms 23772 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 14 ms 23792 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 21 ms 23892 KB Output is correct
26 Correct 15 ms 23772 KB Output is correct
27 Correct 12 ms 23812 KB Output is correct
28 Correct 15 ms 23808 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 12 ms 23808 KB Output is correct
31 Correct 12 ms 23860 KB Output is correct
32 Correct 12 ms 23892 KB Output is correct
33 Correct 12 ms 23764 KB Output is correct
34 Correct 11 ms 23768 KB Output is correct
35 Correct 11 ms 23808 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 12 ms 23828 KB Output is correct
38 Correct 13 ms 23812 KB Output is correct
39 Correct 13 ms 23816 KB Output is correct
40 Correct 13 ms 23892 KB Output is correct
41 Correct 12 ms 23892 KB Output is correct
42 Correct 12 ms 23892 KB Output is correct
43 Correct 11 ms 23804 KB Output is correct
44 Correct 12 ms 23728 KB Output is correct
45 Correct 11 ms 23764 KB Output is correct
46 Correct 11 ms 23764 KB Output is correct
47 Correct 12 ms 23744 KB Output is correct
48 Correct 11 ms 23764 KB Output is correct
49 Correct 12 ms 23780 KB Output is correct
50 Correct 13 ms 23748 KB Output is correct
51 Correct 12 ms 23764 KB Output is correct
52 Correct 13 ms 23800 KB Output is correct
53 Correct 13 ms 23892 KB Output is correct
54 Correct 17 ms 23876 KB Output is correct
55 Correct 12 ms 23828 KB Output is correct
56 Correct 12 ms 23800 KB Output is correct
57 Correct 12 ms 23764 KB Output is correct
58 Correct 12 ms 23804 KB Output is correct
59 Correct 13 ms 23748 KB Output is correct
60 Correct 12 ms 23764 KB Output is correct
61 Correct 13 ms 23740 KB Output is correct
62 Correct 14 ms 23804 KB Output is correct
63 Correct 15 ms 23804 KB Output is correct
64 Correct 12 ms 23764 KB Output is correct
65 Correct 12 ms 23808 KB Output is correct
66 Correct 16 ms 23764 KB Output is correct
67 Correct 14 ms 23764 KB Output is correct
68 Correct 31 ms 28800 KB Output is correct
69 Correct 40 ms 33968 KB Output is correct
70 Correct 16 ms 23764 KB Output is correct
71 Correct 56 ms 39036 KB Output is correct
72 Correct 75 ms 44232 KB Output is correct
73 Correct 86 ms 49332 KB Output is correct
74 Correct 111 ms 54496 KB Output is correct
75 Correct 111 ms 59720 KB Output is correct
76 Correct 126 ms 64808 KB Output is correct
77 Correct 140 ms 69944 KB Output is correct
78 Correct 161 ms 75160 KB Output is correct
79 Correct 177 ms 80336 KB Output is correct
80 Correct 186 ms 85492 KB Output is correct
81 Correct 16 ms 23764 KB Output is correct
82 Correct 225 ms 90588 KB Output is correct
83 Correct 207 ms 95700 KB Output is correct
84 Correct 239 ms 100804 KB Output is correct
85 Correct 256 ms 105996 KB Output is correct
86 Correct 267 ms 111064 KB Output is correct
87 Correct 306 ms 116272 KB Output is correct
88 Correct 371 ms 121368 KB Output is correct
89 Correct 297 ms 126528 KB Output is correct
90 Correct 15 ms 23764 KB Output is correct
91 Correct 13 ms 23836 KB Output is correct
92 Correct 12 ms 23740 KB Output is correct
93 Correct 13 ms 23764 KB Output is correct
94 Correct 12 ms 23788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23716 KB Output is correct
2 Correct 14 ms 23760 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23800 KB Output is correct
7 Correct 14 ms 23764 KB Output is correct
8 Correct 12 ms 23744 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 14 ms 23820 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 12 ms 23816 KB Output is correct
16 Correct 13 ms 23764 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 11 ms 23764 KB Output is correct
20 Correct 11 ms 23732 KB Output is correct
21 Correct 12 ms 23772 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 14 ms 23792 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 21 ms 23892 KB Output is correct
26 Correct 15 ms 23772 KB Output is correct
27 Correct 12 ms 23812 KB Output is correct
28 Correct 15 ms 23808 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 12 ms 23808 KB Output is correct
31 Correct 12 ms 23860 KB Output is correct
32 Correct 12 ms 23892 KB Output is correct
33 Correct 12 ms 23764 KB Output is correct
34 Correct 11 ms 23768 KB Output is correct
35 Correct 11 ms 23808 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 12 ms 23828 KB Output is correct
38 Correct 13 ms 23812 KB Output is correct
39 Correct 13 ms 23816 KB Output is correct
40 Correct 13 ms 23892 KB Output is correct
41 Correct 12 ms 23892 KB Output is correct
42 Correct 12 ms 23892 KB Output is correct
43 Correct 11 ms 23804 KB Output is correct
44 Correct 12 ms 23728 KB Output is correct
45 Correct 11 ms 23764 KB Output is correct
46 Correct 11 ms 23764 KB Output is correct
47 Correct 12 ms 23744 KB Output is correct
48 Incorrect 12 ms 23796 KB Output isn't correct
49 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23716 KB Output is correct
2 Correct 14 ms 23760 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23800 KB Output is correct
7 Correct 14 ms 23764 KB Output is correct
8 Correct 12 ms 23744 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 11 ms 23764 KB Output is correct
13 Correct 14 ms 23820 KB Output is correct
14 Correct 13 ms 23804 KB Output is correct
15 Correct 12 ms 23816 KB Output is correct
16 Correct 13 ms 23764 KB Output is correct
17 Correct 12 ms 23800 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 11 ms 23764 KB Output is correct
20 Correct 11 ms 23732 KB Output is correct
21 Correct 12 ms 23772 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 14 ms 23792 KB Output is correct
24 Correct 12 ms 23764 KB Output is correct
25 Correct 21 ms 23892 KB Output is correct
26 Correct 15 ms 23772 KB Output is correct
27 Correct 12 ms 23812 KB Output is correct
28 Correct 15 ms 23808 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 12 ms 23808 KB Output is correct
31 Correct 12 ms 23860 KB Output is correct
32 Correct 12 ms 23892 KB Output is correct
33 Correct 12 ms 23764 KB Output is correct
34 Correct 11 ms 23768 KB Output is correct
35 Correct 11 ms 23808 KB Output is correct
36 Correct 12 ms 23892 KB Output is correct
37 Correct 12 ms 23828 KB Output is correct
38 Correct 13 ms 23812 KB Output is correct
39 Correct 13 ms 23816 KB Output is correct
40 Correct 13 ms 23892 KB Output is correct
41 Correct 12 ms 23892 KB Output is correct
42 Correct 12 ms 23892 KB Output is correct
43 Correct 11 ms 23804 KB Output is correct
44 Correct 12 ms 23728 KB Output is correct
45 Correct 11 ms 23764 KB Output is correct
46 Correct 11 ms 23764 KB Output is correct
47 Correct 12 ms 23744 KB Output is correct
48 Correct 11 ms 23764 KB Output is correct
49 Correct 12 ms 23780 KB Output is correct
50 Correct 13 ms 23748 KB Output is correct
51 Correct 12 ms 23764 KB Output is correct
52 Correct 13 ms 23800 KB Output is correct
53 Correct 13 ms 23892 KB Output is correct
54 Correct 17 ms 23876 KB Output is correct
55 Correct 12 ms 23828 KB Output is correct
56 Correct 12 ms 23800 KB Output is correct
57 Correct 12 ms 23764 KB Output is correct
58 Correct 12 ms 23804 KB Output is correct
59 Correct 13 ms 23748 KB Output is correct
60 Correct 12 ms 23764 KB Output is correct
61 Correct 13 ms 23740 KB Output is correct
62 Correct 14 ms 23804 KB Output is correct
63 Correct 15 ms 23804 KB Output is correct
64 Correct 12 ms 23764 KB Output is correct
65 Correct 12 ms 23808 KB Output is correct
66 Correct 16 ms 23764 KB Output is correct
67 Correct 14 ms 23764 KB Output is correct
68 Correct 31 ms 28800 KB Output is correct
69 Correct 40 ms 33968 KB Output is correct
70 Correct 16 ms 23764 KB Output is correct
71 Correct 56 ms 39036 KB Output is correct
72 Correct 75 ms 44232 KB Output is correct
73 Correct 86 ms 49332 KB Output is correct
74 Correct 111 ms 54496 KB Output is correct
75 Correct 111 ms 59720 KB Output is correct
76 Correct 126 ms 64808 KB Output is correct
77 Correct 140 ms 69944 KB Output is correct
78 Correct 161 ms 75160 KB Output is correct
79 Correct 177 ms 80336 KB Output is correct
80 Correct 186 ms 85492 KB Output is correct
81 Correct 16 ms 23764 KB Output is correct
82 Correct 225 ms 90588 KB Output is correct
83 Correct 207 ms 95700 KB Output is correct
84 Correct 239 ms 100804 KB Output is correct
85 Correct 256 ms 105996 KB Output is correct
86 Correct 267 ms 111064 KB Output is correct
87 Correct 306 ms 116272 KB Output is correct
88 Correct 371 ms 121368 KB Output is correct
89 Correct 297 ms 126528 KB Output is correct
90 Correct 15 ms 23764 KB Output is correct
91 Correct 13 ms 23836 KB Output is correct
92 Correct 12 ms 23740 KB Output is correct
93 Correct 13 ms 23764 KB Output is correct
94 Correct 12 ms 23788 KB Output is correct
95 Incorrect 12 ms 23796 KB Output isn't correct
96 Halted 0 ms 0 KB -