# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
263234 | 2020-08-13T14:23:22 Z | patrikpavic2 | Designated Cities (JOI19_designated_cities) | C++17 | 718 ms | 53268 KB |
#include <cstdio> #include <cstring> #include <cstdlib> #include <vector> #include <set> #define X first #define Y second #define PB push_back using namespace std; typedef long long ll; typedef pair < int, int > pii; typedef pair < int, pii > pip; const int N = 2e5 + 500; vector < pii > v[N]; vector < pip > v2[N]; set < pair < ll, int > > S; int n, deg[N], bio[N]; ll cur, bst[N]; ll C[N], uk; void start(int x, int lst){ for(pip nxt : v2[x]){ if(nxt.X == lst) continue; C[1] += nxt.Y.X; start(nxt.X, x); } } void dfs(int x, int lst){ for(pip nxt : v2[x]){ if(nxt.X == lst) continue; C[nxt.X] = C[x] - nxt.Y.X + nxt.Y.Y; dfs(nxt.X, x); } bst[1] = max(bst[1], C[x]); } inline int pronadi(int x){ for(pii nxt : v[x]) if(deg[nxt.X]) return nxt.Y; return 0; } int main(){ for(int i = 0;i < N;i++) bst[i] = 1e18; scanf("%d", &n); for(int i = 1;i < n;i++){ int x, y, a, b; scanf("%d%d%d%d", &x, &y, &b, &a); v[x].PB({y, a}); v[y].PB({x, b}); v2[x].PB({y, {a, b}}); v2[y].PB({x, {b, a}}); uk += a + b; deg[x]++; deg[y]++; } for(int i = 1;i <= n;i++){ if(deg[i] == 1) S.insert({v[i][0].Y, i}); } bst[(int)S.size()] = cur; int lisce = (int)S.size(); for(;S.size() > 2;){ int brs = S.begin() -> Y; ll tez = S.begin() -> X; deg[brs] = 0; S.erase(S.begin()); for(pii nxt : v[brs]){ if(deg[nxt.X] > 0){ deg[nxt.X]--; if(deg[nxt.X] == 1) S.insert({pronadi(nxt.X) + tez, nxt.X}); else bst[(int)S.size()] = bst[(int)S.size() + 1] + tez; break; } } } bst[1] = 0; start(1, 1); dfs(1, 1); bst[1] = uk - bst[1]; int q; scanf("%d", &q); for(;q--;){ int x; scanf("%d", &x); x = min(x, lisce); printf("%lld\n", bst[x]); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 11264 KB | Output is correct |
2 | Correct | 7 ms | 11264 KB | Output is correct |
3 | Correct | 8 ms | 11264 KB | Output is correct |
4 | Correct | 9 ms | 11264 KB | Output is correct |
5 | Correct | 7 ms | 11264 KB | Output is correct |
6 | Correct | 7 ms | 11264 KB | Output is correct |
7 | Correct | 7 ms | 11392 KB | Output is correct |
8 | Correct | 7 ms | 11264 KB | Output is correct |
9 | Correct | 7 ms | 11264 KB | Output is correct |
10 | Correct | 8 ms | 11264 KB | Output is correct |
11 | Correct | 7 ms | 11264 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 11264 KB | Output is correct |
2 | Correct | 649 ms | 34232 KB | Output is correct |
3 | Correct | 434 ms | 33912 KB | Output is correct |
4 | Correct | 535 ms | 34424 KB | Output is correct |
5 | Correct | 638 ms | 34840 KB | Output is correct |
6 | Correct | 609 ms | 35520 KB | Output is correct |
7 | Correct | 573 ms | 37020 KB | Output is correct |
8 | Correct | 498 ms | 35192 KB | Output is correct |
9 | Correct | 496 ms | 42640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 11264 KB | Output is correct |
2 | Correct | 610 ms | 34384 KB | Output is correct |
3 | Correct | 434 ms | 41468 KB | Output is correct |
4 | Correct | 570 ms | 39492 KB | Output is correct |
5 | Correct | 621 ms | 41260 KB | Output is correct |
6 | Correct | 624 ms | 41932 KB | Output is correct |
7 | Correct | 526 ms | 47636 KB | Output is correct |
8 | Correct | 492 ms | 43512 KB | Output is correct |
9 | Correct | 477 ms | 48800 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 11264 KB | Output is correct |
2 | Correct | 7 ms | 11264 KB | Output is correct |
3 | Correct | 8 ms | 11264 KB | Output is correct |
4 | Correct | 9 ms | 11264 KB | Output is correct |
5 | Correct | 7 ms | 11264 KB | Output is correct |
6 | Correct | 7 ms | 11264 KB | Output is correct |
7 | Correct | 7 ms | 11392 KB | Output is correct |
8 | Correct | 7 ms | 11264 KB | Output is correct |
9 | Correct | 7 ms | 11264 KB | Output is correct |
10 | Correct | 8 ms | 11264 KB | Output is correct |
11 | Correct | 7 ms | 11264 KB | Output is correct |
12 | Correct | 7 ms | 11264 KB | Output is correct |
13 | Correct | 10 ms | 11552 KB | Output is correct |
14 | Correct | 10 ms | 11520 KB | Output is correct |
15 | Correct | 10 ms | 11648 KB | Output is correct |
16 | Correct | 12 ms | 11600 KB | Output is correct |
17 | Correct | 10 ms | 11648 KB | Output is correct |
18 | Correct | 10 ms | 11648 KB | Output is correct |
19 | Correct | 10 ms | 11648 KB | Output is correct |
20 | Correct | 11 ms | 11648 KB | Output is correct |
21 | Correct | 13 ms | 11648 KB | Output is correct |
22 | Correct | 10 ms | 11648 KB | Output is correct |
23 | Correct | 10 ms | 11648 KB | Output is correct |
24 | Correct | 10 ms | 11648 KB | Output is correct |
25 | Correct | 10 ms | 11648 KB | Output is correct |
26 | Correct | 10 ms | 11776 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 11264 KB | Output is correct |
2 | Correct | 649 ms | 34232 KB | Output is correct |
3 | Correct | 434 ms | 33912 KB | Output is correct |
4 | Correct | 535 ms | 34424 KB | Output is correct |
5 | Correct | 638 ms | 34840 KB | Output is correct |
6 | Correct | 609 ms | 35520 KB | Output is correct |
7 | Correct | 573 ms | 37020 KB | Output is correct |
8 | Correct | 498 ms | 35192 KB | Output is correct |
9 | Correct | 496 ms | 42640 KB | Output is correct |
10 | Correct | 7 ms | 11264 KB | Output is correct |
11 | Correct | 610 ms | 34384 KB | Output is correct |
12 | Correct | 434 ms | 41468 KB | Output is correct |
13 | Correct | 570 ms | 39492 KB | Output is correct |
14 | Correct | 621 ms | 41260 KB | Output is correct |
15 | Correct | 624 ms | 41932 KB | Output is correct |
16 | Correct | 526 ms | 47636 KB | Output is correct |
17 | Correct | 492 ms | 43512 KB | Output is correct |
18 | Correct | 477 ms | 48800 KB | Output is correct |
19 | Correct | 8 ms | 11264 KB | Output is correct |
20 | Correct | 651 ms | 40696 KB | Output is correct |
21 | Correct | 456 ms | 41596 KB | Output is correct |
22 | Correct | 598 ms | 39332 KB | Output is correct |
23 | Correct | 663 ms | 40824 KB | Output is correct |
24 | Correct | 666 ms | 39800 KB | Output is correct |
25 | Correct | 691 ms | 40784 KB | Output is correct |
26 | Correct | 672 ms | 39816 KB | Output is correct |
27 | Correct | 637 ms | 41252 KB | Output is correct |
28 | Correct | 573 ms | 41848 KB | Output is correct |
29 | Correct | 592 ms | 39800 KB | Output is correct |
30 | Correct | 569 ms | 41380 KB | Output is correct |
31 | Correct | 553 ms | 44572 KB | Output is correct |
32 | Correct | 507 ms | 43640 KB | Output is correct |
33 | Correct | 468 ms | 49172 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 11264 KB | Output is correct |
2 | Correct | 7 ms | 11264 KB | Output is correct |
3 | Correct | 8 ms | 11264 KB | Output is correct |
4 | Correct | 9 ms | 11264 KB | Output is correct |
5 | Correct | 7 ms | 11264 KB | Output is correct |
6 | Correct | 7 ms | 11264 KB | Output is correct |
7 | Correct | 7 ms | 11392 KB | Output is correct |
8 | Correct | 7 ms | 11264 KB | Output is correct |
9 | Correct | 7 ms | 11264 KB | Output is correct |
10 | Correct | 8 ms | 11264 KB | Output is correct |
11 | Correct | 7 ms | 11264 KB | Output is correct |
12 | Correct | 7 ms | 11264 KB | Output is correct |
13 | Correct | 649 ms | 34232 KB | Output is correct |
14 | Correct | 434 ms | 33912 KB | Output is correct |
15 | Correct | 535 ms | 34424 KB | Output is correct |
16 | Correct | 638 ms | 34840 KB | Output is correct |
17 | Correct | 609 ms | 35520 KB | Output is correct |
18 | Correct | 573 ms | 37020 KB | Output is correct |
19 | Correct | 498 ms | 35192 KB | Output is correct |
20 | Correct | 496 ms | 42640 KB | Output is correct |
21 | Correct | 7 ms | 11264 KB | Output is correct |
22 | Correct | 610 ms | 34384 KB | Output is correct |
23 | Correct | 434 ms | 41468 KB | Output is correct |
24 | Correct | 570 ms | 39492 KB | Output is correct |
25 | Correct | 621 ms | 41260 KB | Output is correct |
26 | Correct | 624 ms | 41932 KB | Output is correct |
27 | Correct | 526 ms | 47636 KB | Output is correct |
28 | Correct | 492 ms | 43512 KB | Output is correct |
29 | Correct | 477 ms | 48800 KB | Output is correct |
30 | Correct | 7 ms | 11264 KB | Output is correct |
31 | Correct | 10 ms | 11552 KB | Output is correct |
32 | Correct | 10 ms | 11520 KB | Output is correct |
33 | Correct | 10 ms | 11648 KB | Output is correct |
34 | Correct | 12 ms | 11600 KB | Output is correct |
35 | Correct | 10 ms | 11648 KB | Output is correct |
36 | Correct | 10 ms | 11648 KB | Output is correct |
37 | Correct | 10 ms | 11648 KB | Output is correct |
38 | Correct | 11 ms | 11648 KB | Output is correct |
39 | Correct | 13 ms | 11648 KB | Output is correct |
40 | Correct | 10 ms | 11648 KB | Output is correct |
41 | Correct | 10 ms | 11648 KB | Output is correct |
42 | Correct | 10 ms | 11648 KB | Output is correct |
43 | Correct | 10 ms | 11648 KB | Output is correct |
44 | Correct | 10 ms | 11776 KB | Output is correct |
45 | Correct | 8 ms | 11264 KB | Output is correct |
46 | Correct | 651 ms | 40696 KB | Output is correct |
47 | Correct | 456 ms | 41596 KB | Output is correct |
48 | Correct | 598 ms | 39332 KB | Output is correct |
49 | Correct | 663 ms | 40824 KB | Output is correct |
50 | Correct | 666 ms | 39800 KB | Output is correct |
51 | Correct | 691 ms | 40784 KB | Output is correct |
52 | Correct | 672 ms | 39816 KB | Output is correct |
53 | Correct | 637 ms | 41252 KB | Output is correct |
54 | Correct | 573 ms | 41848 KB | Output is correct |
55 | Correct | 592 ms | 39800 KB | Output is correct |
56 | Correct | 569 ms | 41380 KB | Output is correct |
57 | Correct | 553 ms | 44572 KB | Output is correct |
58 | Correct | 507 ms | 43640 KB | Output is correct |
59 | Correct | 468 ms | 49172 KB | Output is correct |
60 | Correct | 7 ms | 11264 KB | Output is correct |
61 | Correct | 655 ms | 43512 KB | Output is correct |
62 | Correct | 485 ms | 42104 KB | Output is correct |
63 | Correct | 625 ms | 41976 KB | Output is correct |
64 | Correct | 684 ms | 43384 KB | Output is correct |
65 | Correct | 718 ms | 42032 KB | Output is correct |
66 | Correct | 680 ms | 43384 KB | Output is correct |
67 | Correct | 640 ms | 42132 KB | Output is correct |
68 | Correct | 647 ms | 43972 KB | Output is correct |
69 | Correct | 643 ms | 44408 KB | Output is correct |
70 | Correct | 669 ms | 41836 KB | Output is correct |
71 | Correct | 698 ms | 44112 KB | Output is correct |
72 | Correct | 658 ms | 47224 KB | Output is correct |
73 | Correct | 572 ms | 45232 KB | Output is correct |
74 | Correct | 610 ms | 53268 KB | Output is correct |