# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
118095 | 2019-06-18T07:28:09 Z | 김세빈(#2888) | Designated Cities (JOI19_designated_cities) | C++14 | 652 ms | 50680 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <ll, ll> pll; priority_queue <pll, vector <pll>, greater <pll>> Q; vector <pll> V[202020], V2[202020]; vector <ll> X, Y; ll P[202020], D[202020], A[202020]; bool chk[202020]; ll n, ans; void dfs1(ll p, ll r) { for(pll &t: V2[p]){ if(t.first != r){ ans += t.second; dfs1(t.first, p); } } } void dfs2(ll p, ll r) { ll i; A[1] = min(A[1], ans); for(i=0; i<V2[p].size(); i++){ if(V2[p][i].first != r){ ans -= V2[p][i].second; ans += V[p][i].second; dfs2(V[p][i].first, p); ans += V2[p][i].second; ans -= V[p][i].second; } } } int main() { ll q, i, u, v, x, y, d; scanf("%lld", &n); for(i=1; i<n; i++){ scanf("%lld%lld%lld%lld", &u, &v, &x, &y); V[u].emplace_back(v, y); V[v].emplace_back(u, x); D[u] ++; D[v] ++; V2[u].emplace_back(v, x); V2[v].emplace_back(u, y); } A[1] = 1e18; dfs1(1, 0); dfs2(1, 0); ans = 0; for(i=1; i<=n; i++){ if(D[i] == 1){ P[i] = V[i][0].first; chk[i] = 1; Q.push(pll(V[i][0].second, i)); } } for(; Q.size() > 2; ){ tie(d, u) = Q.top(); Q.pop(); if(D[P[u]] == 2){ chk[P[u]] = 1; for(pll &t: V[P[u]]){ if(!chk[t.first]){ d += t.second; P[u] = t.first; Q.push(pll(d, u)); break; } } } else{ ans += d; A[Q.size()] = ans; D[P[u]] --; } } scanf("%lld", &q); for(; q--; ){ scanf("%lld", &x); printf("%lld\n", A[x]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 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 | 9856 KB | Output is correct |
5 | Correct | 11 ms | 9856 KB | Output is correct |
6 | Correct | 11 ms | 9856 KB | Output is correct |
7 | Correct | 11 ms | 9856 KB | Output is correct |
8 | Correct | 10 ms | 9856 KB | Output is correct |
9 | Correct | 10 ms | 9856 KB | Output is correct |
10 | Correct | 11 ms | 9856 KB | Output is correct |
11 | Correct | 10 ms | 9856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9856 KB | Output is correct |
2 | Correct | 579 ms | 35700 KB | Output is correct |
3 | Correct | 530 ms | 42616 KB | Output is correct |
4 | Correct | 543 ms | 36644 KB | Output is correct |
5 | Correct | 543 ms | 36876 KB | Output is correct |
6 | Correct | 566 ms | 38636 KB | Output is correct |
7 | Correct | 454 ms | 36528 KB | Output is correct |
8 | Correct | 534 ms | 45684 KB | Output is correct |
9 | Correct | 317 ms | 38464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9856 KB | Output is correct |
2 | Correct | 555 ms | 35596 KB | Output is correct |
3 | Correct | 548 ms | 43384 KB | Output is correct |
4 | Correct | 546 ms | 35664 KB | Output is correct |
5 | Correct | 542 ms | 35872 KB | Output is correct |
6 | Correct | 633 ms | 37840 KB | Output is correct |
7 | Correct | 355 ms | 37696 KB | Output is correct |
8 | Correct | 552 ms | 42580 KB | Output is correct |
9 | Correct | 318 ms | 37444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 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 | 9856 KB | Output is correct |
5 | Correct | 11 ms | 9856 KB | Output is correct |
6 | Correct | 11 ms | 9856 KB | Output is correct |
7 | Correct | 11 ms | 9856 KB | Output is correct |
8 | Correct | 10 ms | 9856 KB | Output is correct |
9 | Correct | 10 ms | 9856 KB | Output is correct |
10 | Correct | 11 ms | 9856 KB | Output is correct |
11 | Correct | 10 ms | 9856 KB | Output is correct |
12 | Correct | 10 ms | 9856 KB | Output is correct |
13 | Correct | 13 ms | 10240 KB | Output is correct |
14 | Correct | 13 ms | 10240 KB | Output is correct |
15 | Correct | 12 ms | 10112 KB | Output is correct |
16 | Correct | 12 ms | 10240 KB | Output is correct |
17 | Correct | 12 ms | 10112 KB | Output is correct |
18 | Correct | 12 ms | 10240 KB | Output is correct |
19 | Correct | 12 ms | 10240 KB | Output is correct |
20 | Correct | 13 ms | 10284 KB | Output is correct |
21 | Correct | 12 ms | 10240 KB | Output is correct |
22 | Correct | 12 ms | 10240 KB | Output is correct |
23 | Correct | 12 ms | 10240 KB | Output is correct |
24 | Correct | 12 ms | 10240 KB | Output is correct |
25 | Correct | 12 ms | 10240 KB | Output is correct |
26 | Correct | 12 ms | 10240 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9856 KB | Output is correct |
2 | Correct | 579 ms | 35700 KB | Output is correct |
3 | Correct | 530 ms | 42616 KB | Output is correct |
4 | Correct | 543 ms | 36644 KB | Output is correct |
5 | Correct | 543 ms | 36876 KB | Output is correct |
6 | Correct | 566 ms | 38636 KB | Output is correct |
7 | Correct | 454 ms | 36528 KB | Output is correct |
8 | Correct | 534 ms | 45684 KB | Output is correct |
9 | Correct | 317 ms | 38464 KB | Output is correct |
10 | Correct | 9 ms | 9856 KB | Output is correct |
11 | Correct | 555 ms | 35596 KB | Output is correct |
12 | Correct | 548 ms | 43384 KB | Output is correct |
13 | Correct | 546 ms | 35664 KB | Output is correct |
14 | Correct | 542 ms | 35872 KB | Output is correct |
15 | Correct | 633 ms | 37840 KB | Output is correct |
16 | Correct | 355 ms | 37696 KB | Output is correct |
17 | Correct | 552 ms | 42580 KB | Output is correct |
18 | Correct | 318 ms | 37444 KB | Output is correct |
19 | Correct | 9 ms | 9880 KB | Output is correct |
20 | Correct | 572 ms | 42028 KB | Output is correct |
21 | Correct | 553 ms | 49992 KB | Output is correct |
22 | Correct | 527 ms | 40776 KB | Output is correct |
23 | Correct | 565 ms | 42624 KB | Output is correct |
24 | Correct | 568 ms | 41572 KB | Output is correct |
25 | Correct | 559 ms | 42700 KB | Output is correct |
26 | Correct | 601 ms | 41600 KB | Output is correct |
27 | Correct | 551 ms | 42404 KB | Output is correct |
28 | Correct | 568 ms | 44052 KB | Output is correct |
29 | Correct | 598 ms | 43128 KB | Output is correct |
30 | Correct | 553 ms | 41364 KB | Output is correct |
31 | Correct | 453 ms | 42820 KB | Output is correct |
32 | Correct | 581 ms | 49388 KB | Output is correct |
33 | Correct | 338 ms | 44116 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 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 | 9856 KB | Output is correct |
5 | Correct | 11 ms | 9856 KB | Output is correct |
6 | Correct | 11 ms | 9856 KB | Output is correct |
7 | Correct | 11 ms | 9856 KB | Output is correct |
8 | Correct | 10 ms | 9856 KB | Output is correct |
9 | Correct | 10 ms | 9856 KB | Output is correct |
10 | Correct | 11 ms | 9856 KB | Output is correct |
11 | Correct | 10 ms | 9856 KB | Output is correct |
12 | Correct | 10 ms | 9856 KB | Output is correct |
13 | Correct | 579 ms | 35700 KB | Output is correct |
14 | Correct | 530 ms | 42616 KB | Output is correct |
15 | Correct | 543 ms | 36644 KB | Output is correct |
16 | Correct | 543 ms | 36876 KB | Output is correct |
17 | Correct | 566 ms | 38636 KB | Output is correct |
18 | Correct | 454 ms | 36528 KB | Output is correct |
19 | Correct | 534 ms | 45684 KB | Output is correct |
20 | Correct | 317 ms | 38464 KB | Output is correct |
21 | Correct | 9 ms | 9856 KB | Output is correct |
22 | Correct | 555 ms | 35596 KB | Output is correct |
23 | Correct | 548 ms | 43384 KB | Output is correct |
24 | Correct | 546 ms | 35664 KB | Output is correct |
25 | Correct | 542 ms | 35872 KB | Output is correct |
26 | Correct | 633 ms | 37840 KB | Output is correct |
27 | Correct | 355 ms | 37696 KB | Output is correct |
28 | Correct | 552 ms | 42580 KB | Output is correct |
29 | Correct | 318 ms | 37444 KB | Output is correct |
30 | Correct | 10 ms | 9856 KB | Output is correct |
31 | Correct | 13 ms | 10240 KB | Output is correct |
32 | Correct | 13 ms | 10240 KB | Output is correct |
33 | Correct | 12 ms | 10112 KB | Output is correct |
34 | Correct | 12 ms | 10240 KB | Output is correct |
35 | Correct | 12 ms | 10112 KB | Output is correct |
36 | Correct | 12 ms | 10240 KB | Output is correct |
37 | Correct | 12 ms | 10240 KB | Output is correct |
38 | Correct | 13 ms | 10284 KB | Output is correct |
39 | Correct | 12 ms | 10240 KB | Output is correct |
40 | Correct | 12 ms | 10240 KB | Output is correct |
41 | Correct | 12 ms | 10240 KB | Output is correct |
42 | Correct | 12 ms | 10240 KB | Output is correct |
43 | Correct | 12 ms | 10240 KB | Output is correct |
44 | Correct | 12 ms | 10240 KB | Output is correct |
45 | Correct | 9 ms | 9880 KB | Output is correct |
46 | Correct | 572 ms | 42028 KB | Output is correct |
47 | Correct | 553 ms | 49992 KB | Output is correct |
48 | Correct | 527 ms | 40776 KB | Output is correct |
49 | Correct | 565 ms | 42624 KB | Output is correct |
50 | Correct | 568 ms | 41572 KB | Output is correct |
51 | Correct | 559 ms | 42700 KB | Output is correct |
52 | Correct | 601 ms | 41600 KB | Output is correct |
53 | Correct | 551 ms | 42404 KB | Output is correct |
54 | Correct | 568 ms | 44052 KB | Output is correct |
55 | Correct | 598 ms | 43128 KB | Output is correct |
56 | Correct | 553 ms | 41364 KB | Output is correct |
57 | Correct | 453 ms | 42820 KB | Output is correct |
58 | Correct | 581 ms | 49388 KB | Output is correct |
59 | Correct | 338 ms | 44116 KB | Output is correct |
60 | Correct | 11 ms | 9888 KB | Output is correct |
61 | Correct | 605 ms | 44580 KB | Output is correct |
62 | Correct | 592 ms | 49808 KB | Output is correct |
63 | Correct | 585 ms | 43264 KB | Output is correct |
64 | Correct | 623 ms | 45180 KB | Output is correct |
65 | Correct | 609 ms | 43780 KB | Output is correct |
66 | Correct | 643 ms | 45244 KB | Output is correct |
67 | Correct | 652 ms | 43908 KB | Output is correct |
68 | Correct | 617 ms | 45124 KB | Output is correct |
69 | Correct | 620 ms | 46528 KB | Output is correct |
70 | Correct | 629 ms | 45404 KB | Output is correct |
71 | Correct | 566 ms | 43964 KB | Output is correct |
72 | Correct | 514 ms | 45392 KB | Output is correct |
73 | Correct | 597 ms | 50680 KB | Output is correct |
74 | Correct | 382 ms | 47388 KB | Output is correct |