QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533917 | #1490. Road Closures | Nika533 | 0 | 91ms | 7552kb | C++17 | 1.3kb | 2024-08-26 16:49:40 | 2024-08-26 16:49:40 |
Judging History
answer
#include "roads.h"
#include <bits/stdc++.h>
using namespace std;
const int NN=1e5+5;
int n;
long long dp[NN][2];
vector<pair<int,int>> g[NN];
void dfs(int x, int p, int k) {
vector<long long> v; long long val=0;
for (auto AA:g[x]) {
int y=AA.first,w=AA.second;
if (y==p) continue;
dfs(y,x,k);
val+=dp[y][0]; v.push_back(w-max(0ll,dp[y][0]-dp[y][1]));
}
int sz=v.size();
sort(v.begin(),v.end()); reverse(v.begin(),v.end());
dp[x][0]=val; dp[x][1]=val;
if (x==0) {
for (int i=sz-1; i>=k; i--) dp[x][0]+=v[i];
for (int i=sz-1; i>=k+1; i--) dp[x][1]+=v[i];
}
else {
if (k==0) dp[x][0]=1e15;
else for (int i=sz-1; i>=k-1; i--) dp[x][0]+=v[i];
for (int i=sz-1; i>=k; i--) dp[x][1]+=v[i];
}
}
long long solve(int k) {
dfs(0,0,k);
// for (int i=0; i<n; i++) cout<<i<<" "<<dp[i][1]<<" "<<dp[i][0]<<endl;
return dp[0][0];
}
vector<long long> minimum_closure_costs(int N, vector<int> U, vector<int> V, vector<int> W) {
vector<long long> ans(N,0); n=N;
for (int i=0; i<N; i++) {
g[U[i]].emplace_back(V[i],W[i]);
g[V[i]].emplace_back(U[i],W[i]);
}
for (int k=0; k<n; k++) ans[k]=solve(k);
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 5
Accepted
time: 91ms
memory: 6600kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 2000 0 559 717769868 0 237 766447943 0 122 517523402 0 1779 560381127 0 1477 566064983 0 67 303410673 0 1869 605544497 0 1769 774963386 0 457 469996896 0 201 995323973 0 1694 885366346 0 1547 362843462 0 55 947026157 0 1302 448837561 0 733 673028958 0 1139 65...
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 1239932930636 1238933034699 1237933274404 1236933811304 1235934429141 1234937111512 1233940392882 1232944051225 1231948294381 1230952540572 1229957216599 1228962389458 1227967672340 1226973261544 1225980503037 1224988213004 1223996200036 1223004619782 1222...
result:
ok 3 lines
Test #2:
score: 5
Accepted
time: 45ms
memory: 7552kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 2000 0 1442 1000000000 0 1429 1000000000 0 446 1000000000 0 149 1000000000 0 1530 1000000000 0 527 1000000000 0 859 1000000000 0 297 1000000000 0 1575 1000000000 0 900 1000000000 0 1792 1000000000 0 1962 1000000000 0 1566 1000000000 0 1372 1000000000 0 1538 1...
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 1999000000000 1998000000000 1997000000000 1996000000000 1995000000000 1994000000000 1993000000000 1992000000000 1991000000000 1990000000000 1989000000000 1988000000000 1987000000000 1986000000000 1985000000000 1984000000000 1983000000000 1982000000000 1981...
result:
ok 3 lines
Test #3:
score: 5
Accepted
time: 2ms
memory: 7468kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 136 0 120 700717317 0 123 718572676 0 132 959462853 0 107 530118580 0 9 969226913 0 82 871844182 0 84 845338769 0 65 892873084 0 128 633096137 0 42 505691290 0 62 551920432 0 69 901803199 0 71 543402077 0 22 684844125 0 38 696996987 0 108 824527065 0 58 70901...
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 99836216760 98851977125 97870361891 96897562987 95925870841 94956643928 93989200634 93027802434 92068339581 91108999837 90153109803 89203933069 88257991949 87313068234 86374187295 85435928745 84501934377 83572524493 82645816813 81733435400 80822405308 7991...
result:
ok 3 lines
Test #4:
score: 5
Accepted
time: 2ms
memory: 7324kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 200 0 77 391886950 0 57 553091833 0 80 906348882 0 40 506652307 0 184 338560594 0 87 380862436 0 170 684734760 0 191 857396956 0 27 637257239 0 185 529164085 0 33 458571287 0 133 769321525 0 41 671206065 0 166 200260384 0 189 210065789 0 23 512103998 0 18 622...
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 100983628068 99984459468 98998058529 98013796639 97032988739 96054503035 95078925288 94109019082 93145666200 92183527659 91225019525 90269487976 89324715876 88404499721 87495915174 86589566292 85686021041 84789119369 83893847847 82999595315 82140298258 812...
result:
ok 3 lines
Test #5:
score: 5
Accepted
time: 0ms
memory: 7248kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 200 0 194 1000000000 0 127 1000000000 0 165 1000000000 0 93 1000000000 0 103 1000000000 0 27 1000000000 0 77 1000000000 0 7 1000000000 0 15 1000000000 0 1 1000000000 0 173 1000000000 0 149 1000000000 0 86 1000000000 0 67 1000000000 0 133 1000000000 0 75 10000...
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 199000000000 198000000000 197000000000 196000000000 195000000000 194000000000 193000000000 192000000000 191000000000 190000000000 189000000000 188000000000 187000000000 186000000000 185000000000 184000000000 183000000000 182000000000 181000000000 180000000...
result:
ok 3 lines
Test #6:
score: 5
Accepted
time: 35ms
memory: 6660kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 1685 0 416 6 0 1238 7 0 1121 5 0 192 9 0 308 5 0 948 7 0 762 7 0 1413 10 0 214 7 0 1607 7 0 376 5 0 1169 7 0 385 7 0 150 9 0 542 10 0 50 10 0 1206 6 0 434 7 0 618 5 0 768 10 0 1355 6 0 1561 8 0 121 5 0 1011 10 0 1150 9 0 1230 10 0 1372 8 0 536 10 0 1000 6 0 7...
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 12587 12577 12567 12557 12547 12537 12527 12517 12507 12497 12487 12477 12467 12457 12447 12437 12427 12417 12407 12397 12387 12377 12367 12357 12347 12337 12327 12317 12307 12297 12287 12277 12267 12257 12247 12237 12227 12217 12207 12197 12187 12177 1216...
result:
ok 3 lines
Test #7:
score: 5
Accepted
time: 50ms
memory: 7488kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 2000 0 1639 4 0 905 3 0 1918 7 0 1730 6 0 792 5 0 275 5 0 79 6 0 1555 3 0 1679 7 0 777 9 0 1790 10 0 1749 3 0 1430 4 0 1091 7 0 1598 8 0 738 10 0 342 6 0 1454 7 0 933 5 0 252 2 0 762 8 0 1224 4 0 156 5 0 227 10 0 791 3 0 1183 3 0 1937 10 0 1279 9 0 1773 4 0 1...
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 10930 10920 10910 10900 10890 10880 10870 10860 10850 10840 10830 10820 10810 10800 10790 10780 10770 10760 10750 10740 10730 10720 10710 10700 10690 10680 10670 10660 10650 10640 10630 10620 10610 10600 10590 10580 10570 10560 10550 10540 10530 10520 1051...
result:
ok 3 lines
Test #8:
score: 5
Accepted
time: 2ms
memory: 6160kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 188 0 73 7 0 161 7 0 172 10 0 88 8 0 180 9 0 81 7 0 28 8 0 92 8 0 57 7 0 66 10 0 108 8 0 156 10 0 142 8 0 65 6 0 130 6 0 166 6 0 132 7 0 43 7 0 87 7 0 171 8 0 53 5 0 151 9 0 68 5 0 37 8 0 67 9 0 99 5 0 15 5 0 148 10 0 31 7 0 46 8 0 23 5 0 162 5 0 168 6 0 136 ...
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 1376 1366 1356 1346 1336 1326 1316 1306 1296 1286 1276 1266 1256 1246 1236 1226 1216 1206 1196 1186 1176 1166 1156 1146 1136 1126 1117 1108 1099 1090 1081 1072 1063 1054 1045 1036 1027 1018 1009 1000 991 982 973 964 955 946 937 928 919 910 901 892 883 874 ...
result:
ok 3 lines
Test #9:
score: 5
Accepted
time: 2ms
memory: 7188kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 200 0 40 10 0 17 9 0 71 8 0 61 3 0 126 5 0 47 1 0 64 8 0 128 6 0 25 2 0 168 5 0 196 1 0 75 3 0 177 9 0 190 8 0 197 3 0 97 10 0 19 2 0 187 8 0 48 1 0 4 9 0 154 4 0 94 5 0 141 6 0 68 8 0 143 5 0 5 8 0 172 2 0 155 1 0 112 7 0 72 1 0 33 8 0 127 8 0 101 9 0 108 3 ...
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 1110 1100 1090 1080 1070 1060 1050 1040 1030 1020 1010 1000 990 980 970 960 950 940 930 920 911 902 893 884 875 866 857 848 839 830 821 812 803 794 785 776 767 758 749 740 731 722 714 706 698 690 682 674 666 658 650 642 634 626 618 610 602 594 586 578 570 ...
result:
ok 3 lines
Test #10:
score: 0
Time Limit Exceeded
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 60145 0 38832 8 0 33327 7 0 10015 8 0 32059 7 0 2920 8 0 25980 10 0 12777 6 0 49541 10 0 16526 9 0 31021 10 0 43794 7 0 2769 5 0 27040 5 0 57465 10 0 7213 6 0 5285 6 0 17505 9 0 38268 8 0 39509 5 0 33647 5 0 43349 6 0 16916 5 0 52054 7 0 34160 6 0 19654 5 0 5...
output:
Unauthorized output
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #19:
score: 7
Accepted
time: 1ms
memory: 6112kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 2 0 1 4
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 4 0
result:
ok 3 lines
Test #20:
score: 0
Time Limit Exceeded
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 82978 0 1 687749865 1 2 811016969 2 3 502155590 3 4 930576294 4 5 879987412 5 6 883450944 6 7 975772046 7 8 739249697 8 9 954502114 9 10 962223056 10 11 562948742 11 12 933819577 12 13 614418299 13 14 724040317 14 15 798630312 15 16 583709944 16 17 634442427 ...
output:
Unauthorized output
result:
Subtask #3:
score: 0
Wrong Answer
Test #34:
score: 14
Accepted
time: 1ms
memory: 6112kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 2 0 1 4
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 4 0
result:
ok 3 lines
Test #35:
score: 14
Accepted
time: 1ms
memory: 6508kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 5 0 1 1 0 2 4 0 3 3 2 4 2
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 10 5 1 0 0
result:
ok 3 lines
Test #36:
score: 14
Accepted
time: 1ms
memory: 7428kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 4 0 1 5 2 0 10 0 3 5
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 20 10 5 0
result:
ok 3 lines
Test #37:
score: 0
Wrong Answer
time: 2ms
memory: 6208kb
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 150 107 123 877656381 75 23 954037632 23 0 751950653 15 3 886375777 18 44 979176984 59 26 735548230 94 75 977809165 12 93 589331204 116 149 874044974 40 42 998026262 99 142 937689560 2 121 955527621 6 16 696503256 137 136 966670903 93 30 543967244 148 18 5618...
output:
064bde9ff69ddc34b3b45c2d26d58873d85290d3 OK 112502233251 61480101900 24158095276 7205365011 2670369795 1131009335 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 3rd lines differ - expected: '112502233251 61480101900 23849...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '112502233251 61480101900 24158...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #79:
score: 0
Time Limit Exceeded
input:
c10234cabdfd6eae47773fb6f163e0350fc797e1 96680 81008 32770 1 53103 75975 1 38090 49649 1 35805 25778 1 50058 68261 1 52213 58881 1 52672 34310 1 1080 42408 1 32306 82599 1 73623 7340 1 87691 42161 1 78365 96557 1 78654 88488 1 5875 25925 1 23217 85743 1 18698 42579 1 90401 84720 1 45973 91271 1 5282...
output:
Unauthorized output
result:
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%