# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
118236 | 2019-06-18T12:04:58 Z | songc | Designated Cities (JOI19_designated_cities) | C++14 | 696 ms | 46860 KB |
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL, int> pii; int N, Q; vector<pii> G[202020], RG[202020]; int deg[202020]; bool chk[202020]; LL ans[202020], sum; priority_queue<pii> PQ; LL d(int u, int p){ LL ret = 0; for (pii v : RG[u]) if (v.second != p) ret += d(v.second, u) + v.first; return ret; } void f(int u, int p){ ans[1] = min(ans[1], sum); for (int i=0; i<(int)G[u].size(); i++){ if (G[u][i].second == p) continue; sum -= RG[u][i].first; sum += G[u][i].first; f(G[u][i].second, u); sum += RG[u][i].first; sum -= G[u][i].first; } } int main(){ int u, v; LL x, y; scanf("%d", &N); for (int i=1; i<N; i++){ scanf("%d %d %lld %lld", &u, &v, &x, &y); G[u].push_back(pii(y, v)); G[v].push_back(pii(x, u)); RG[v].push_back(pii(y, u)); RG[u].push_back(pii(x, v)); deg[u]++, deg[v]++; } for (int i=1; i<=N; i++) if (deg[i] == 1) PQ.push(pii(-G[i][0].first, i)); while (PQ.size()>2){ pii T = PQ.top(); PQ.pop(); chk[T.second] = true; for (pii it : G[T.second]){ if (!chk[it.second]){ u = it.second; break; } } deg[u]--; if (deg[u] == 1){ for (pii it : G[u]){ if (!chk[it.second]){ PQ.push(pii(T.first-it.first, u)); break; } } continue; } ans[PQ.size()] = ans[PQ.size()+1] - T.first; } ans[1] = 1234567890123456ll; sum = d(1, 0); f(1, 0); scanf("%d", &Q); while (Q--){ scanf("%d", &u); printf("%lld\n", ans[u]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9856 KB | Output is correct |
2 | Correct | 10 ms | 9856 KB | Output is correct |
3 | Correct | 10 ms | 9856 KB | Output is correct |
4 | Correct | 10 ms | 9828 KB | Output is correct |
5 | Correct | 11 ms | 9828 KB | Output is correct |
6 | Correct | 10 ms | 9856 KB | Output is correct |
7 | Correct | 11 ms | 9828 KB | Output is correct |
8 | Correct | 11 ms | 9856 KB | Output is correct |
9 | Correct | 10 ms | 9856 KB | Output is correct |
10 | Correct | 9 ms | 9856 KB | Output is correct |
11 | Correct | 9 ms | 9856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9856 KB | Output is correct |
2 | Correct | 628 ms | 33876 KB | Output is correct |
3 | Correct | 572 ms | 42652 KB | Output is correct |
4 | Correct | 583 ms | 34284 KB | Output is correct |
5 | Correct | 594 ms | 34688 KB | Output is correct |
6 | Correct | 636 ms | 36168 KB | Output is correct |
7 | Correct | 525 ms | 34352 KB | Output is correct |
8 | Correct | 588 ms | 43768 KB | Output is correct |
9 | Correct | 419 ms | 36716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9856 KB | Output is correct |
2 | Correct | 628 ms | 33956 KB | Output is correct |
3 | Correct | 584 ms | 43784 KB | Output is correct |
4 | Correct | 597 ms | 33892 KB | Output is correct |
5 | Correct | 608 ms | 34012 KB | Output is correct |
6 | Correct | 644 ms | 35964 KB | Output is correct |
7 | Correct | 442 ms | 36136 KB | Output is correct |
8 | Correct | 580 ms | 40688 KB | Output is correct |
9 | Correct | 400 ms | 36284 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9856 KB | Output is correct |
2 | Correct | 10 ms | 9856 KB | Output is correct |
3 | Correct | 10 ms | 9856 KB | Output is correct |
4 | Correct | 10 ms | 9828 KB | Output is correct |
5 | Correct | 11 ms | 9828 KB | Output is correct |
6 | Correct | 10 ms | 9856 KB | Output is correct |
7 | Correct | 11 ms | 9828 KB | Output is correct |
8 | Correct | 11 ms | 9856 KB | Output is correct |
9 | Correct | 10 ms | 9856 KB | Output is correct |
10 | Correct | 9 ms | 9856 KB | Output is correct |
11 | Correct | 9 ms | 9856 KB | Output is correct |
12 | Correct | 9 ms | 9856 KB | Output is correct |
13 | Correct | 12 ms | 10112 KB | Output is correct |
14 | Correct | 12 ms | 10112 KB | Output is correct |
15 | Correct | 13 ms | 10112 KB | Output is correct |
16 | Correct | 12 ms | 10112 KB | Output is correct |
17 | Correct | 12 ms | 10112 KB | Output is correct |
18 | Correct | 13 ms | 10112 KB | Output is correct |
19 | Correct | 13 ms | 10112 KB | Output is correct |
20 | Correct | 13 ms | 10112 KB | Output is correct |
21 | Correct | 13 ms | 10112 KB | Output is correct |
22 | Correct | 13 ms | 10112 KB | Output is correct |
23 | Correct | 13 ms | 10112 KB | Output is correct |
24 | Correct | 12 ms | 10112 KB | Output is correct |
25 | Correct | 14 ms | 10240 KB | Output is correct |
26 | Correct | 12 ms | 10104 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9856 KB | Output is correct |
2 | Correct | 628 ms | 33876 KB | Output is correct |
3 | Correct | 572 ms | 42652 KB | Output is correct |
4 | Correct | 583 ms | 34284 KB | Output is correct |
5 | Correct | 594 ms | 34688 KB | Output is correct |
6 | Correct | 636 ms | 36168 KB | Output is correct |
7 | Correct | 525 ms | 34352 KB | Output is correct |
8 | Correct | 588 ms | 43768 KB | Output is correct |
9 | Correct | 419 ms | 36716 KB | Output is correct |
10 | Correct | 9 ms | 9856 KB | Output is correct |
11 | Correct | 628 ms | 33956 KB | Output is correct |
12 | Correct | 584 ms | 43784 KB | Output is correct |
13 | Correct | 597 ms | 33892 KB | Output is correct |
14 | Correct | 608 ms | 34012 KB | Output is correct |
15 | Correct | 644 ms | 35964 KB | Output is correct |
16 | Correct | 442 ms | 36136 KB | Output is correct |
17 | Correct | 580 ms | 40688 KB | Output is correct |
18 | Correct | 400 ms | 36284 KB | Output is correct |
19 | Correct | 10 ms | 9856 KB | Output is correct |
20 | Correct | 618 ms | 34472 KB | Output is correct |
21 | Correct | 582 ms | 46860 KB | Output is correct |
22 | Correct | 593 ms | 36720 KB | Output is correct |
23 | Correct | 653 ms | 37232 KB | Output is correct |
24 | Correct | 630 ms | 37360 KB | Output is correct |
25 | Correct | 633 ms | 37216 KB | Output is correct |
26 | Correct | 669 ms | 37316 KB | Output is correct |
27 | Correct | 578 ms | 36932 KB | Output is correct |
28 | Correct | 606 ms | 38540 KB | Output is correct |
29 | Correct | 639 ms | 37388 KB | Output is correct |
30 | Correct | 571 ms | 37036 KB | Output is correct |
31 | Correct | 495 ms | 37460 KB | Output is correct |
32 | Correct | 629 ms | 43756 KB | Output is correct |
33 | Correct | 400 ms | 38852 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9856 KB | Output is correct |
2 | Correct | 10 ms | 9856 KB | Output is correct |
3 | Correct | 10 ms | 9856 KB | Output is correct |
4 | Correct | 10 ms | 9828 KB | Output is correct |
5 | Correct | 11 ms | 9828 KB | Output is correct |
6 | Correct | 10 ms | 9856 KB | Output is correct |
7 | Correct | 11 ms | 9828 KB | Output is correct |
8 | Correct | 11 ms | 9856 KB | Output is correct |
9 | Correct | 10 ms | 9856 KB | Output is correct |
10 | Correct | 9 ms | 9856 KB | Output is correct |
11 | Correct | 9 ms | 9856 KB | Output is correct |
12 | Correct | 10 ms | 9856 KB | Output is correct |
13 | Correct | 628 ms | 33876 KB | Output is correct |
14 | Correct | 572 ms | 42652 KB | Output is correct |
15 | Correct | 583 ms | 34284 KB | Output is correct |
16 | Correct | 594 ms | 34688 KB | Output is correct |
17 | Correct | 636 ms | 36168 KB | Output is correct |
18 | Correct | 525 ms | 34352 KB | Output is correct |
19 | Correct | 588 ms | 43768 KB | Output is correct |
20 | Correct | 419 ms | 36716 KB | Output is correct |
21 | Correct | 9 ms | 9856 KB | Output is correct |
22 | Correct | 628 ms | 33956 KB | Output is correct |
23 | Correct | 584 ms | 43784 KB | Output is correct |
24 | Correct | 597 ms | 33892 KB | Output is correct |
25 | Correct | 608 ms | 34012 KB | Output is correct |
26 | Correct | 644 ms | 35964 KB | Output is correct |
27 | Correct | 442 ms | 36136 KB | Output is correct |
28 | Correct | 580 ms | 40688 KB | Output is correct |
29 | Correct | 400 ms | 36284 KB | Output is correct |
30 | Correct | 9 ms | 9856 KB | Output is correct |
31 | Correct | 12 ms | 10112 KB | Output is correct |
32 | Correct | 12 ms | 10112 KB | Output is correct |
33 | Correct | 13 ms | 10112 KB | Output is correct |
34 | Correct | 12 ms | 10112 KB | Output is correct |
35 | Correct | 12 ms | 10112 KB | Output is correct |
36 | Correct | 13 ms | 10112 KB | Output is correct |
37 | Correct | 13 ms | 10112 KB | Output is correct |
38 | Correct | 13 ms | 10112 KB | Output is correct |
39 | Correct | 13 ms | 10112 KB | Output is correct |
40 | Correct | 13 ms | 10112 KB | Output is correct |
41 | Correct | 13 ms | 10112 KB | Output is correct |
42 | Correct | 12 ms | 10112 KB | Output is correct |
43 | Correct | 14 ms | 10240 KB | Output is correct |
44 | Correct | 12 ms | 10104 KB | Output is correct |
45 | Correct | 10 ms | 9856 KB | Output is correct |
46 | Correct | 618 ms | 34472 KB | Output is correct |
47 | Correct | 582 ms | 46860 KB | Output is correct |
48 | Correct | 593 ms | 36720 KB | Output is correct |
49 | Correct | 653 ms | 37232 KB | Output is correct |
50 | Correct | 630 ms | 37360 KB | Output is correct |
51 | Correct | 633 ms | 37216 KB | Output is correct |
52 | Correct | 669 ms | 37316 KB | Output is correct |
53 | Correct | 578 ms | 36932 KB | Output is correct |
54 | Correct | 606 ms | 38540 KB | Output is correct |
55 | Correct | 639 ms | 37388 KB | Output is correct |
56 | Correct | 571 ms | 37036 KB | Output is correct |
57 | Correct | 495 ms | 37460 KB | Output is correct |
58 | Correct | 629 ms | 43756 KB | Output is correct |
59 | Correct | 400 ms | 38852 KB | Output is correct |
60 | Correct | 11 ms | 9856 KB | Output is correct |
61 | Correct | 696 ms | 37708 KB | Output is correct |
62 | Correct | 609 ms | 45300 KB | Output is correct |
63 | Correct | 608 ms | 37988 KB | Output is correct |
64 | Correct | 644 ms | 38244 KB | Output is correct |
65 | Correct | 691 ms | 38156 KB | Output is correct |
66 | Correct | 649 ms | 38464 KB | Output is correct |
67 | Correct | 681 ms | 38120 KB | Output is correct |
68 | Correct | 659 ms | 38340 KB | Output is correct |
69 | Correct | 674 ms | 39368 KB | Output is correct |
70 | Correct | 676 ms | 38248 KB | Output is correct |
71 | Correct | 663 ms | 38108 KB | Output is correct |
72 | Correct | 583 ms | 38400 KB | Output is correct |
73 | Correct | 633 ms | 43632 KB | Output is correct |
74 | Correct | 438 ms | 40376 KB | Output is correct |