Submission #427326

# Submission time Handle Problem Language Result Execution time Memory
427326 2021-06-14T14:21:08 Z cpp219 Traffic (IOI10_traffic) C++14
50 / 100
649 ms 262144 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 = 1e9 + 7;
const ll Log2 = 20;
typedef pair<ll,ll> LL;
vector<ll> g[N];
ll n,a[N],mn = inf,chosen,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;
}

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 70724 KB Output is correct
2 Correct 46 ms 70696 KB Output is correct
3 Correct 46 ms 70728 KB Output is correct
4 Correct 42 ms 70776 KB Output is correct
5 Correct 42 ms 70724 KB Output is correct
6 Correct 44 ms 70708 KB Output is correct
7 Correct 54 ms 70700 KB Output is correct
8 Correct 40 ms 70724 KB Output is correct
9 Correct 41 ms 70732 KB Output is correct
10 Correct 45 ms 70772 KB Output is correct
11 Correct 42 ms 70704 KB Output is correct
12 Correct 42 ms 70712 KB Output is correct
13 Correct 42 ms 70732 KB Output is correct
14 Correct 47 ms 70760 KB Output is correct
15 Correct 39 ms 70720 KB Output is correct
16 Correct 45 ms 70772 KB Output is correct
17 Correct 43 ms 70680 KB Output is correct
18 Correct 46 ms 70784 KB Output is correct
19 Correct 47 ms 70652 KB Output is correct
20 Correct 55 ms 70724 KB Output is correct
21 Correct 46 ms 70760 KB Output is correct
22 Correct 43 ms 70784 KB Output is correct
23 Correct 41 ms 70772 KB Output is correct
24 Correct 43 ms 70724 KB Output is correct
25 Correct 47 ms 70884 KB Output is correct
26 Correct 44 ms 70728 KB Output is correct
27 Correct 46 ms 70832 KB Output is correct
28 Correct 41 ms 70736 KB Output is correct
29 Correct 47 ms 70980 KB Output is correct
30 Correct 46 ms 70852 KB Output is correct
31 Correct 49 ms 70808 KB Output is correct
32 Correct 48 ms 70884 KB Output is correct
33 Correct 51 ms 70852 KB Output is correct
34 Correct 41 ms 70684 KB Output is correct
35 Correct 44 ms 70920 KB Output is correct
36 Correct 46 ms 70864 KB Output is correct
37 Correct 46 ms 70940 KB Output is correct
38 Correct 50 ms 70924 KB Output is correct
39 Correct 65 ms 70852 KB Output is correct
40 Correct 55 ms 70976 KB Output is correct
41 Correct 43 ms 70980 KB Output is correct
42 Correct 41 ms 70984 KB Output is correct
43 Correct 45 ms 70712 KB Output is correct
44 Correct 44 ms 70776 KB Output is correct
45 Correct 44 ms 70724 KB Output is correct
46 Correct 45 ms 70732 KB Output is correct
47 Correct 43 ms 70776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 70724 KB Output is correct
2 Correct 46 ms 70696 KB Output is correct
3 Correct 46 ms 70728 KB Output is correct
4 Correct 42 ms 70776 KB Output is correct
5 Correct 42 ms 70724 KB Output is correct
6 Correct 44 ms 70708 KB Output is correct
7 Correct 54 ms 70700 KB Output is correct
8 Correct 40 ms 70724 KB Output is correct
9 Correct 41 ms 70732 KB Output is correct
10 Correct 45 ms 70772 KB Output is correct
11 Correct 42 ms 70704 KB Output is correct
12 Correct 42 ms 70712 KB Output is correct
13 Correct 42 ms 70732 KB Output is correct
14 Correct 47 ms 70760 KB Output is correct
15 Correct 39 ms 70720 KB Output is correct
16 Correct 45 ms 70772 KB Output is correct
17 Correct 43 ms 70680 KB Output is correct
18 Correct 46 ms 70784 KB Output is correct
19 Correct 47 ms 70652 KB Output is correct
20 Correct 55 ms 70724 KB Output is correct
21 Correct 46 ms 70760 KB Output is correct
22 Correct 43 ms 70784 KB Output is correct
23 Correct 41 ms 70772 KB Output is correct
24 Correct 43 ms 70724 KB Output is correct
25 Correct 47 ms 70884 KB Output is correct
26 Correct 44 ms 70728 KB Output is correct
27 Correct 46 ms 70832 KB Output is correct
28 Correct 41 ms 70736 KB Output is correct
29 Correct 47 ms 70980 KB Output is correct
30 Correct 46 ms 70852 KB Output is correct
31 Correct 49 ms 70808 KB Output is correct
32 Correct 48 ms 70884 KB Output is correct
33 Correct 51 ms 70852 KB Output is correct
34 Correct 41 ms 70684 KB Output is correct
35 Correct 44 ms 70920 KB Output is correct
36 Correct 46 ms 70864 KB Output is correct
37 Correct 46 ms 70940 KB Output is correct
38 Correct 50 ms 70924 KB Output is correct
39 Correct 65 ms 70852 KB Output is correct
40 Correct 55 ms 70976 KB Output is correct
41 Correct 43 ms 70980 KB Output is correct
42 Correct 41 ms 70984 KB Output is correct
43 Correct 45 ms 70712 KB Output is correct
44 Correct 44 ms 70776 KB Output is correct
45 Correct 44 ms 70724 KB Output is correct
46 Correct 45 ms 70732 KB Output is correct
47 Correct 43 ms 70776 KB Output is correct
48 Correct 46 ms 70672 KB Output is correct
49 Correct 42 ms 70776 KB Output is correct
50 Correct 47 ms 70724 KB Output is correct
51 Correct 42 ms 70744 KB Output is correct
52 Correct 52 ms 70776 KB Output is correct
53 Correct 49 ms 70752 KB Output is correct
54 Correct 48 ms 70780 KB Output is correct
55 Correct 41 ms 70768 KB Output is correct
56 Correct 42 ms 70760 KB Output is correct
57 Correct 41 ms 70724 KB Output is correct
58 Correct 44 ms 70708 KB Output is correct
59 Correct 44 ms 70704 KB Output is correct
60 Correct 46 ms 70756 KB Output is correct
61 Correct 48 ms 70676 KB Output is correct
62 Correct 49 ms 70776 KB Output is correct
63 Correct 42 ms 70764 KB Output is correct
64 Correct 41 ms 70728 KB Output is correct
65 Correct 43 ms 70764 KB Output is correct
66 Correct 47 ms 70748 KB Output is correct
67 Correct 50 ms 70776 KB Output is correct
68 Correct 101 ms 83024 KB Output is correct
69 Correct 114 ms 95152 KB Output is correct
70 Correct 45 ms 70772 KB Output is correct
71 Correct 190 ms 107392 KB Output is correct
72 Correct 179 ms 119556 KB Output is correct
73 Correct 243 ms 131920 KB Output is correct
74 Correct 290 ms 144172 KB Output is correct
75 Correct 320 ms 156432 KB Output is correct
76 Correct 413 ms 168696 KB Output is correct
77 Correct 393 ms 180940 KB Output is correct
78 Correct 446 ms 193196 KB Output is correct
79 Correct 459 ms 205352 KB Output is correct
80 Correct 496 ms 217608 KB Output is correct
81 Correct 49 ms 70724 KB Output is correct
82 Correct 536 ms 229856 KB Output is correct
83 Correct 595 ms 242148 KB Output is correct
84 Correct 649 ms 254404 KB Output is correct
85 Correct 624 ms 262144 KB Output is correct
86 Runtime error 572 ms 262144 KB Execution killed with signal 9
87 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 70724 KB Output is correct
2 Correct 46 ms 70696 KB Output is correct
3 Correct 46 ms 70728 KB Output is correct
4 Correct 42 ms 70776 KB Output is correct
5 Correct 42 ms 70724 KB Output is correct
6 Correct 44 ms 70708 KB Output is correct
7 Correct 54 ms 70700 KB Output is correct
8 Correct 40 ms 70724 KB Output is correct
9 Correct 41 ms 70732 KB Output is correct
10 Correct 45 ms 70772 KB Output is correct
11 Correct 42 ms 70704 KB Output is correct
12 Correct 42 ms 70712 KB Output is correct
13 Correct 42 ms 70732 KB Output is correct
14 Correct 47 ms 70760 KB Output is correct
15 Correct 39 ms 70720 KB Output is correct
16 Correct 45 ms 70772 KB Output is correct
17 Correct 43 ms 70680 KB Output is correct
18 Correct 46 ms 70784 KB Output is correct
19 Correct 47 ms 70652 KB Output is correct
20 Correct 55 ms 70724 KB Output is correct
21 Correct 46 ms 70760 KB Output is correct
22 Correct 43 ms 70784 KB Output is correct
23 Correct 41 ms 70772 KB Output is correct
24 Correct 43 ms 70724 KB Output is correct
25 Correct 47 ms 70884 KB Output is correct
26 Correct 44 ms 70728 KB Output is correct
27 Correct 46 ms 70832 KB Output is correct
28 Correct 41 ms 70736 KB Output is correct
29 Correct 47 ms 70980 KB Output is correct
30 Correct 46 ms 70852 KB Output is correct
31 Correct 49 ms 70808 KB Output is correct
32 Correct 48 ms 70884 KB Output is correct
33 Correct 51 ms 70852 KB Output is correct
34 Correct 41 ms 70684 KB Output is correct
35 Correct 44 ms 70920 KB Output is correct
36 Correct 46 ms 70864 KB Output is correct
37 Correct 46 ms 70940 KB Output is correct
38 Correct 50 ms 70924 KB Output is correct
39 Correct 65 ms 70852 KB Output is correct
40 Correct 55 ms 70976 KB Output is correct
41 Correct 43 ms 70980 KB Output is correct
42 Correct 41 ms 70984 KB Output is correct
43 Correct 45 ms 70712 KB Output is correct
44 Correct 44 ms 70776 KB Output is correct
45 Correct 44 ms 70724 KB Output is correct
46 Correct 45 ms 70732 KB Output is correct
47 Correct 43 ms 70776 KB Output is correct
48 Correct 47 ms 70708 KB Output is correct
49 Correct 46 ms 70716 KB Output is correct
50 Correct 48 ms 70688 KB Output is correct
51 Correct 47 ms 70756 KB Output is correct
52 Correct 48 ms 70724 KB Output is correct
53 Correct 50 ms 70692 KB Output is correct
54 Correct 48 ms 70684 KB Output is correct
55 Correct 41 ms 70772 KB Output is correct
56 Correct 44 ms 70688 KB Output is correct
57 Correct 48 ms 70724 KB Output is correct
58 Correct 47 ms 70724 KB Output is correct
59 Correct 41 ms 70732 KB Output is correct
60 Correct 41 ms 70732 KB Output is correct
61 Correct 40 ms 70720 KB Output is correct
62 Correct 41 ms 70716 KB Output is correct
63 Correct 53 ms 70668 KB Output is correct
64 Correct 42 ms 70696 KB Output is correct
65 Correct 41 ms 70748 KB Output is correct
66 Correct 41 ms 70736 KB Output is correct
67 Correct 43 ms 70764 KB Output is correct
68 Correct 42 ms 70724 KB Output is correct
69 Correct 42 ms 70756 KB Output is correct
70 Correct 42 ms 70688 KB Output is correct
71 Correct 43 ms 70720 KB Output is correct
72 Correct 44 ms 70776 KB Output is correct
73 Correct 49 ms 70708 KB Output is correct
74 Correct 42 ms 70728 KB Output is correct
75 Correct 49 ms 70724 KB Output is correct
76 Correct 43 ms 70756 KB Output is correct
77 Correct 41 ms 70712 KB Output is correct
78 Correct 44 ms 70732 KB Output is correct
79 Correct 46 ms 70740 KB Output is correct
80 Correct 51 ms 70740 KB Output is correct
81 Correct 45 ms 70744 KB Output is correct
82 Correct 49 ms 70808 KB Output is correct
83 Correct 44 ms 70748 KB Output is correct
84 Correct 45 ms 70828 KB Output is correct
85 Correct 47 ms 70820 KB Output is correct
86 Correct 45 ms 70872 KB Output is correct
87 Correct 48 ms 70816 KB Output is correct
88 Correct 48 ms 70804 KB Output is correct
89 Correct 47 ms 70880 KB Output is correct
90 Correct 44 ms 70852 KB Output is correct
91 Correct 45 ms 70816 KB Output is correct
92 Correct 43 ms 70668 KB Output is correct
93 Correct 43 ms 70804 KB Output is correct
94 Correct 46 ms 70844 KB Output is correct
95 Correct 50 ms 70996 KB Output is correct
96 Correct 45 ms 70768 KB Output is correct
97 Correct 43 ms 70688 KB Output is correct
98 Correct 45 ms 70664 KB Output is correct
99 Correct 49 ms 70756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 70724 KB Output is correct
2 Correct 46 ms 70696 KB Output is correct
3 Correct 46 ms 70728 KB Output is correct
4 Correct 42 ms 70776 KB Output is correct
5 Correct 42 ms 70724 KB Output is correct
6 Correct 44 ms 70708 KB Output is correct
7 Correct 54 ms 70700 KB Output is correct
8 Correct 40 ms 70724 KB Output is correct
9 Correct 41 ms 70732 KB Output is correct
10 Correct 45 ms 70772 KB Output is correct
11 Correct 42 ms 70704 KB Output is correct
12 Correct 42 ms 70712 KB Output is correct
13 Correct 42 ms 70732 KB Output is correct
14 Correct 47 ms 70760 KB Output is correct
15 Correct 39 ms 70720 KB Output is correct
16 Correct 45 ms 70772 KB Output is correct
17 Correct 43 ms 70680 KB Output is correct
18 Correct 46 ms 70784 KB Output is correct
19 Correct 47 ms 70652 KB Output is correct
20 Correct 55 ms 70724 KB Output is correct
21 Correct 46 ms 70760 KB Output is correct
22 Correct 43 ms 70784 KB Output is correct
23 Correct 41 ms 70772 KB Output is correct
24 Correct 43 ms 70724 KB Output is correct
25 Correct 47 ms 70884 KB Output is correct
26 Correct 44 ms 70728 KB Output is correct
27 Correct 46 ms 70832 KB Output is correct
28 Correct 41 ms 70736 KB Output is correct
29 Correct 47 ms 70980 KB Output is correct
30 Correct 46 ms 70852 KB Output is correct
31 Correct 49 ms 70808 KB Output is correct
32 Correct 48 ms 70884 KB Output is correct
33 Correct 51 ms 70852 KB Output is correct
34 Correct 41 ms 70684 KB Output is correct
35 Correct 44 ms 70920 KB Output is correct
36 Correct 46 ms 70864 KB Output is correct
37 Correct 46 ms 70940 KB Output is correct
38 Correct 50 ms 70924 KB Output is correct
39 Correct 65 ms 70852 KB Output is correct
40 Correct 55 ms 70976 KB Output is correct
41 Correct 43 ms 70980 KB Output is correct
42 Correct 41 ms 70984 KB Output is correct
43 Correct 45 ms 70712 KB Output is correct
44 Correct 44 ms 70776 KB Output is correct
45 Correct 44 ms 70724 KB Output is correct
46 Correct 45 ms 70732 KB Output is correct
47 Correct 43 ms 70776 KB Output is correct
48 Correct 46 ms 70672 KB Output is correct
49 Correct 42 ms 70776 KB Output is correct
50 Correct 47 ms 70724 KB Output is correct
51 Correct 42 ms 70744 KB Output is correct
52 Correct 52 ms 70776 KB Output is correct
53 Correct 49 ms 70752 KB Output is correct
54 Correct 48 ms 70780 KB Output is correct
55 Correct 41 ms 70768 KB Output is correct
56 Correct 42 ms 70760 KB Output is correct
57 Correct 41 ms 70724 KB Output is correct
58 Correct 44 ms 70708 KB Output is correct
59 Correct 44 ms 70704 KB Output is correct
60 Correct 46 ms 70756 KB Output is correct
61 Correct 48 ms 70676 KB Output is correct
62 Correct 49 ms 70776 KB Output is correct
63 Correct 42 ms 70764 KB Output is correct
64 Correct 41 ms 70728 KB Output is correct
65 Correct 43 ms 70764 KB Output is correct
66 Correct 47 ms 70748 KB Output is correct
67 Correct 50 ms 70776 KB Output is correct
68 Correct 101 ms 83024 KB Output is correct
69 Correct 114 ms 95152 KB Output is correct
70 Correct 45 ms 70772 KB Output is correct
71 Correct 190 ms 107392 KB Output is correct
72 Correct 179 ms 119556 KB Output is correct
73 Correct 243 ms 131920 KB Output is correct
74 Correct 290 ms 144172 KB Output is correct
75 Correct 320 ms 156432 KB Output is correct
76 Correct 413 ms 168696 KB Output is correct
77 Correct 393 ms 180940 KB Output is correct
78 Correct 446 ms 193196 KB Output is correct
79 Correct 459 ms 205352 KB Output is correct
80 Correct 496 ms 217608 KB Output is correct
81 Correct 49 ms 70724 KB Output is correct
82 Correct 536 ms 229856 KB Output is correct
83 Correct 595 ms 242148 KB Output is correct
84 Correct 649 ms 254404 KB Output is correct
85 Correct 624 ms 262144 KB Output is correct
86 Runtime error 572 ms 262144 KB Execution killed with signal 9
87 Halted 0 ms 0 KB -