Submission #427375

# Submission time Handle Problem Language Result Execution time Memory
427375 2021-06-14T14:40:50 Z cpp219 Traffic (IOI10_traffic) C++14
0 / 100
57 ms 70996 KB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e6 + 9;
const ll inf = INT_MAX;
const ll Log2 = 20;
typedef pair<ll,ll> LL;
vector<ll> g[N];
ll n,a[N],mn = inf,chosen = 1,child[N],InitChild[N],sum;
set<LL> s[N];

void DFSinit(ll u,ll p){
    child[u] = a[u];
    for (auto i : g[u]){
        if (i == p) continue;
        DFSinit(i,u); child[u] += child[i];
        s[u].insert({child[i],i});
    }
    InitChild[u] = child[u];
}

void DFS(ll u,ll p){
    if (!s[u].empty()){
        LL now = *s[u].rbegin(),rm = {sum - child[u],-1};
        now = max(now,rm);
        if (now.fs < mn) mn = now.fs,chosen = u;
    }
    for (auto i : g[u]){
        if (i == p) continue;
        s[u].erase({child[i],i}); s[i].insert({sum - child[i],u});
        //cout<<child[i]<<" "<<i; exit(0);
        child[u] = sum - child[i]; child[i] = sum;
        DFS(i,u);
    }
    if (p >= 0){
        child[u] = InitChild[u];
        s[p].insert({child[u],u}); s[u].erase({child[p],p});
        child[p] = InitChild[p];
    }
}

ll LocateCentre(ll sz,ll P[],ll X[],ll Y[]){
    n = sz;
    for (ll i = 0;i < n;i++) a[i] = P[i],sum += a[i];
    for (ll i = 0;i < n - 1;i++){
        g[X[i]].push_back(Y[i]); g[Y[i]].push_back(X[i]);
    }
    DFSinit(0,-1); DFS(0,-1);
    return chosen;
}
/*
ll sz,X[N],Y[N],P[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>sz;
    for (ll i = 0;i < sz;i++) cin>>P[i];
    for (ll i = 0;i < sz - 1;i++) cin>>X[i]>>Y[i];
    cout<<LocateCentre(sz,P,X,Y);
}
*/

Compilation message

traffic.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
traffic.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      |
# Verdict Execution time Memory Grader output
1 Correct 47 ms 70688 KB Output is correct
2 Correct 48 ms 70756 KB Output is correct
3 Correct 48 ms 70724 KB Output is correct
4 Correct 48 ms 70760 KB Output is correct
5 Correct 50 ms 70728 KB Output is correct
6 Correct 44 ms 70672 KB Output is correct
7 Correct 47 ms 70772 KB Output is correct
8 Correct 50 ms 70704 KB Output is correct
9 Correct 48 ms 70772 KB Output is correct
10 Correct 53 ms 70680 KB Output is correct
11 Correct 53 ms 70688 KB Output is correct
12 Correct 54 ms 70768 KB Output is correct
13 Correct 48 ms 70676 KB Output is correct
14 Correct 44 ms 70704 KB Output is correct
15 Correct 53 ms 70680 KB Output is correct
16 Correct 48 ms 70768 KB Output is correct
17 Correct 52 ms 70788 KB Output is correct
18 Correct 50 ms 70684 KB Output is correct
19 Correct 55 ms 70724 KB Output is correct
20 Correct 53 ms 70768 KB Output is correct
21 Correct 48 ms 70776 KB Output is correct
22 Correct 57 ms 70788 KB Output is correct
23 Correct 49 ms 70712 KB Output is correct
24 Correct 49 ms 70744 KB Output is correct
25 Correct 52 ms 70800 KB Output is correct
26 Correct 53 ms 70764 KB Output is correct
27 Correct 49 ms 70836 KB Output is correct
28 Correct 55 ms 70744 KB Output is correct
29 Correct 55 ms 70852 KB Output is correct
30 Correct 55 ms 70868 KB Output is correct
31 Correct 55 ms 70868 KB Output is correct
32 Correct 49 ms 70856 KB Output is correct
33 Correct 51 ms 70780 KB Output is correct
34 Correct 52 ms 70688 KB Output is correct
35 Correct 47 ms 70900 KB Output is correct
36 Correct 47 ms 70860 KB Output is correct
37 Correct 49 ms 70836 KB Output is correct
38 Correct 53 ms 70872 KB Output is correct
39 Correct 57 ms 70972 KB Output is correct
40 Correct 49 ms 70948 KB Output is correct
41 Correct 54 ms 70936 KB Output is correct
42 Correct 49 ms 70996 KB Output is correct
43 Incorrect 50 ms 70760 KB Output isn't correct
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 70688 KB Output is correct
2 Correct 48 ms 70756 KB Output is correct
3 Correct 48 ms 70724 KB Output is correct
4 Correct 48 ms 70760 KB Output is correct
5 Correct 50 ms 70728 KB Output is correct
6 Correct 44 ms 70672 KB Output is correct
7 Correct 47 ms 70772 KB Output is correct
8 Correct 50 ms 70704 KB Output is correct
9 Correct 48 ms 70772 KB Output is correct
10 Correct 53 ms 70680 KB Output is correct
11 Correct 53 ms 70688 KB Output is correct
12 Correct 54 ms 70768 KB Output is correct
13 Correct 48 ms 70676 KB Output is correct
14 Correct 44 ms 70704 KB Output is correct
15 Correct 53 ms 70680 KB Output is correct
16 Correct 48 ms 70768 KB Output is correct
17 Correct 52 ms 70788 KB Output is correct
18 Correct 50 ms 70684 KB Output is correct
19 Correct 55 ms 70724 KB Output is correct
20 Correct 53 ms 70768 KB Output is correct
21 Correct 48 ms 70776 KB Output is correct
22 Correct 57 ms 70788 KB Output is correct
23 Correct 49 ms 70712 KB Output is correct
24 Correct 49 ms 70744 KB Output is correct
25 Correct 52 ms 70800 KB Output is correct
26 Correct 53 ms 70764 KB Output is correct
27 Correct 49 ms 70836 KB Output is correct
28 Correct 55 ms 70744 KB Output is correct
29 Correct 55 ms 70852 KB Output is correct
30 Correct 55 ms 70868 KB Output is correct
31 Correct 55 ms 70868 KB Output is correct
32 Correct 49 ms 70856 KB Output is correct
33 Correct 51 ms 70780 KB Output is correct
34 Correct 52 ms 70688 KB Output is correct
35 Correct 47 ms 70900 KB Output is correct
36 Correct 47 ms 70860 KB Output is correct
37 Correct 49 ms 70836 KB Output is correct
38 Correct 53 ms 70872 KB Output is correct
39 Correct 57 ms 70972 KB Output is correct
40 Correct 49 ms 70948 KB Output is correct
41 Correct 54 ms 70936 KB Output is correct
42 Correct 49 ms 70996 KB Output is correct
43 Incorrect 50 ms 70760 KB Output isn't correct
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 70688 KB Output is correct
2 Correct 48 ms 70756 KB Output is correct
3 Correct 48 ms 70724 KB Output is correct
4 Correct 48 ms 70760 KB Output is correct
5 Correct 50 ms 70728 KB Output is correct
6 Correct 44 ms 70672 KB Output is correct
7 Correct 47 ms 70772 KB Output is correct
8 Correct 50 ms 70704 KB Output is correct
9 Correct 48 ms 70772 KB Output is correct
10 Correct 53 ms 70680 KB Output is correct
11 Correct 53 ms 70688 KB Output is correct
12 Correct 54 ms 70768 KB Output is correct
13 Correct 48 ms 70676 KB Output is correct
14 Correct 44 ms 70704 KB Output is correct
15 Correct 53 ms 70680 KB Output is correct
16 Correct 48 ms 70768 KB Output is correct
17 Correct 52 ms 70788 KB Output is correct
18 Correct 50 ms 70684 KB Output is correct
19 Correct 55 ms 70724 KB Output is correct
20 Correct 53 ms 70768 KB Output is correct
21 Correct 48 ms 70776 KB Output is correct
22 Correct 57 ms 70788 KB Output is correct
23 Correct 49 ms 70712 KB Output is correct
24 Correct 49 ms 70744 KB Output is correct
25 Correct 52 ms 70800 KB Output is correct
26 Correct 53 ms 70764 KB Output is correct
27 Correct 49 ms 70836 KB Output is correct
28 Correct 55 ms 70744 KB Output is correct
29 Correct 55 ms 70852 KB Output is correct
30 Correct 55 ms 70868 KB Output is correct
31 Correct 55 ms 70868 KB Output is correct
32 Correct 49 ms 70856 KB Output is correct
33 Correct 51 ms 70780 KB Output is correct
34 Correct 52 ms 70688 KB Output is correct
35 Correct 47 ms 70900 KB Output is correct
36 Correct 47 ms 70860 KB Output is correct
37 Correct 49 ms 70836 KB Output is correct
38 Correct 53 ms 70872 KB Output is correct
39 Correct 57 ms 70972 KB Output is correct
40 Correct 49 ms 70948 KB Output is correct
41 Correct 54 ms 70936 KB Output is correct
42 Correct 49 ms 70996 KB Output is correct
43 Incorrect 50 ms 70760 KB Output isn't correct
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 70688 KB Output is correct
2 Correct 48 ms 70756 KB Output is correct
3 Correct 48 ms 70724 KB Output is correct
4 Correct 48 ms 70760 KB Output is correct
5 Correct 50 ms 70728 KB Output is correct
6 Correct 44 ms 70672 KB Output is correct
7 Correct 47 ms 70772 KB Output is correct
8 Correct 50 ms 70704 KB Output is correct
9 Correct 48 ms 70772 KB Output is correct
10 Correct 53 ms 70680 KB Output is correct
11 Correct 53 ms 70688 KB Output is correct
12 Correct 54 ms 70768 KB Output is correct
13 Correct 48 ms 70676 KB Output is correct
14 Correct 44 ms 70704 KB Output is correct
15 Correct 53 ms 70680 KB Output is correct
16 Correct 48 ms 70768 KB Output is correct
17 Correct 52 ms 70788 KB Output is correct
18 Correct 50 ms 70684 KB Output is correct
19 Correct 55 ms 70724 KB Output is correct
20 Correct 53 ms 70768 KB Output is correct
21 Correct 48 ms 70776 KB Output is correct
22 Correct 57 ms 70788 KB Output is correct
23 Correct 49 ms 70712 KB Output is correct
24 Correct 49 ms 70744 KB Output is correct
25 Correct 52 ms 70800 KB Output is correct
26 Correct 53 ms 70764 KB Output is correct
27 Correct 49 ms 70836 KB Output is correct
28 Correct 55 ms 70744 KB Output is correct
29 Correct 55 ms 70852 KB Output is correct
30 Correct 55 ms 70868 KB Output is correct
31 Correct 55 ms 70868 KB Output is correct
32 Correct 49 ms 70856 KB Output is correct
33 Correct 51 ms 70780 KB Output is correct
34 Correct 52 ms 70688 KB Output is correct
35 Correct 47 ms 70900 KB Output is correct
36 Correct 47 ms 70860 KB Output is correct
37 Correct 49 ms 70836 KB Output is correct
38 Correct 53 ms 70872 KB Output is correct
39 Correct 57 ms 70972 KB Output is correct
40 Correct 49 ms 70948 KB Output is correct
41 Correct 54 ms 70936 KB Output is correct
42 Correct 49 ms 70996 KB Output is correct
43 Incorrect 50 ms 70760 KB Output isn't correct
44 Halted 0 ms 0 KB -