QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#757729 | #9713. Kill the tree | propane# | AC ✓ | 119ms | 53156kb | C++20 | 1.6kb | 2024-11-17 12:53:14 | 2024-11-17 12:53:16 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<vector<int> > g(n + 1);
for(int i = 0; i < n - 1; i++){
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> mx(n + 1), sz(n + 1), fa(n + 1), son(n + 1);
vector<vector<int> > ans(n + 1);
auto dfs = [&](auto &&dfs, int u) -> void {
sz[u] = 1;
int heavy = 0;
for(auto j : g[u]){
if (j == fa[u]) continue;
fa[j] = u;
dfs(dfs, j);
sz[u] += sz[j];
if (sz[j] > sz[heavy]) heavy = j;
}
son[u] = heavy;
mx[u] = sz[heavy];
if (mx[u] * 2 <= sz[u]){
ans[u].push_back(u);
if (mx[u] * 2 == sz[u]){
ans[u].push_back(son[u]);
}
}
else{
int t = ans[heavy][0];
while((sz[u] - sz[t]) * 2 > sz[u]) t = fa[t];
ans[u].push_back(t);
if ((sz[u] - sz[t]) * 2 == sz[u]) ans[u].push_back(fa[t]);
else if (sz[son[t]] * 2 == sz[u]) ans[u].push_back(son[t]);
}
sort(ans[u].begin(), ans[u].end());
};
dfs(dfs, 1);
for(int i = 1; i <= n; i++){
for(auto x : ans[i]) cout << x << ' ';
cout << '\n';
}
}
详细
Test #1:
score: 100
Accepted
time: 106ms
memory: 40548kb
input:
200000 42924 18271 60536 154257 107175 95680 196335 71607 158051 155259 110869 30974 143595 43516 4228 138046 26249 183847 123888 199873 15009 25362 166527 175160 15257 67159 124779 199363 148904 54047 5988 18123 58281 40739 44562 143880 72819 132492 137782 29662 130741 78276 55073 93292 82700 18328...
output:
1 134385 45886 143670 106649 126220 44121 108393 5226 95313 116080 147311 141180 147983 7428 74120 161963 3879 178499 162544 171549 144413 127262 133093 188325 171802 43558 28179 125217 140604 186651 45633 176397 26425 3745 26982 30063 128965 19661 148036 141733 115691 3...
result:
ok 300000 numbers
Test #2:
score: 0
Accepted
time: 86ms
memory: 28376kb
input:
199996 50563 93215 168370 114785 10263 27279 167398 102988 69456 154440 153717 68545 58173 55699 138929 65580 167561 150907 112977 167988 79291 640 48647 123744 72178 137000 137037 197496 118383 75650 122661 82805 123795 74071 33761 152979 196839 174414 142905 129453 90791 156172 58774 116668 54562 ...
output:
52308 2 3 149366 5 39986 6 175524 45794 8 9 192952 11 12 15527 13 66009 15 14252 16 17 18 67537 71401 20 194399 22 23 112561 24 25 96681 27 28 29 30 31 32 33 34 121482 35 36 37 31661 38 39 40 167372 41 42 6258 43 44 162689 121781 46 47 109092 49 50 5...
result:
ok 245567 numbers
Test #3:
score: 0
Accepted
time: 119ms
memory: 40616kb
input:
199999 108115 63899 151140 109826 91734 90746 4789 43702 33490 139879 66022 34391 70745 83003 112801 142528 9886 183319 176856 131953 87922 32742 91697 98619 67568 5172 174467 29463 160402 64195 108947 34849 175846 12092 78485 126382 24049 57058 61718 193440 158622 23001 153818 1106 129489 57771 110...
output:
1 48291 97907 124184 157340 44928 104142 113149 25406 60681 125505 111209 128945 33452 75396 34973 142246 20449 81918 182248 89473 100884 133111 119943 141764 129724 124892 151908 155499 30095 62682 87555 65387 70067 192746 137092 146200 182945 35587 4212 116219 72444 12...
result:
ok 299997 numbers
Test #4:
score: 0
Accepted
time: 106ms
memory: 28204kb
input:
200000 48572 177918 102783 173305 121844 105171 79011 64874 19642 74839 134908 82174 155124 13643 151930 64210 76846 104574 53671 16053 108054 124925 165270 90267 142571 47673 74135 85118 110373 82490 38223 50928 150689 103342 108645 87946 116240 191522 114026 184255 15616 59120 57708 162149 73127 1...
output:
116957 2 95664 23758 73224 161835 6 7 8 9 10164 10 3557 3399 13 91254 15 175229 17 18 109471 20 197580 22 23 41894 24 61237 25 26 104228 142866 181381 29 52945 117626 26591 152942 40358 62903 34 35 36 37 38 157460 40 121288 87683 199023 44 45 46 47 3871...
result:
ok 247094 numbers
Test #5:
score: 0
Accepted
time: 95ms
memory: 48812kb
input:
199999 172127 91132 183003 46785 6385 80633 66513 82123 55733 180928 160030 7548 48886 90651 126214 87878 64547 137764 105153 49725 133339 32960 91331 126453 75367 3624 155636 113928 189740 20145 105309 69507 29442 84645 123661 144260 58194 93449 65480 128564 171086 158662 154010 64470 96600 198587 ...
output:
65555 104964 144272 79084 133789 29920 176674 42586 71263 101879 3438 15356 73901 194943 26904 171947 19816 90053 14226 71090 167253 90358 159345 21019 87971 37432 70726 193611 121421 9265 129828 64116 184365 39037 99000 85258 152220 60586 195560 149692 74207 125168 188219 ...
result:
ok 299997 numbers
Test #6:
score: 0
Accepted
time: 113ms
memory: 43028kb
input:
200000 110958 26650 98973 119254 97354 127992 136745 138126 78343 726 150950 32977 18539 63304 3284 38518 29231 141415 145250 183698 119703 45467 50645 94214 167477 133445 137689 12515 165446 116008 51988 4894 128134 173796 138783 34735 37780 36404 137362 143072 29573 38029 171767 123010 103717 7192...
output:
140304 152402 146287 109468 164573 34602 154989 108900 94006 95475 11345 6769 125187 33745 144678 59367 131827 145290 188863 99926 101085 98010 102636 101902 45636 190297 67469 120956 106327 158883 92771 118681 136863 90097 168930 161821 185538 142246 66289 125767 174959 1...
result:
ok 300000 numbers
Test #7:
score: 0
Accepted
time: 81ms
memory: 28812kb
input:
199996 117295 27451 144269 75801 75335 138412 129281 196866 105183 18781 123543 63374 30174 187214 90187 175735 190201 21555 40196 57259 102600 65754 121119 195313 32605 86152 152437 1016 126108 185145 196964 90871 87230 169243 106604 19698 119296 89973 70009 188730 143592 32208 149616 98967 61704 4...
output:
184646 2 3 4 5 6 7 8 9 10 11 12 139797 13 14 15 16 17 18 19 20 21 22 23 24 16406 25 195641 26 27 28 29 30 31 32 33 34 35 175162 36 147638 37 38 39 40 41 42 43 44 45 46 47 48 39979 49 50 51 20219 52 104867 53 54 55 56 57 58 59 60 61 62 63 ...
result:
ok 220773 numbers
Test #8:
score: 0
Accepted
time: 76ms
memory: 29024kb
input:
199999 152806 149490 38877 141267 191036 7807 118933 185003 126369 178138 199565 180072 65911 30582 175723 65922 121466 93358 74348 135002 5017 142174 103863 122907 185003 29435 169110 65106 103591 155346 81350 140510 185727 150049 135104 32439 145860 17431 174844 36774 154127 102737 88448 176413 17...
output:
121383 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 113331 7...
result:
ok 202417 numbers
Test #9:
score: 0
Accepted
time: 92ms
memory: 28808kb
input:
199998 38179 38076 68409 15576 53432 180805 99393 171502 149570 17030 11833 102785 82597 99349 167506 113691 6699 84357 54408 37250 52624 83391 158616 80402 184239 189933 138517 28877 161969 92491 13801 108500 118344 146522 152041 114168 170340 147448 140116 46925 8875 182886 138481 3231 30439 50483...
output:
63649 2 95288 67556 5 150957 177569 47569 9 34603 179233 12 5028 13 42030 48021 16 17 141239 19 59299 14981 22 23 24 61746 25 126633 27 78260 28 11575 30 80910 31 32 33 12226 34 163505 35 36 114982 170707 186606 13243 176600 39 9493 23125 41 189863 101557 77...
result:
ok 246661 numbers
Test #10:
score: 0
Accepted
time: 71ms
memory: 29284kb
input:
199998 16838 169384 184759 85943 65527 176616 42656 22266 192144 52163 159482 80488 151972 110151 97425 107901 81348 131462 120676 148223 158041 185010 178442 12753 57367 189680 24223 165904 136941 114235 22773 42133 99329 151424 43318 20970 24313 197457 62964 43596 193009 119682 172560 151909 85321...
output:
78600 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 7...
result:
ok 200363 numbers
Test #11:
score: 0
Accepted
time: 93ms
memory: 28096kb
input:
200000 164193 193239 105802 17956 9783 89463 41897 96787 129037 188320 63703 100141 129876 5484 188993 196573 171761 22379 104447 18990 184624 182384 61311 16337 60143 43509 145200 199406 189749 80103 89639 126651 191295 61402 179498 100036 169473 145174 123514 153270 172310 75734 82487 70488 172636...
output:
58861 179724 3 4 5 6 7 8 9 10 11 12 31469 61148 14 15 16 12387 22791 3757 154294 36270 105729 21 111444 22 23 24 25 127307 165521 56303 29 10905 31 5723 143634 15400 106688 153737 35 83166 105971 7855 38 151779 39 52534 40 41 74233 42 146148 189359 180961 ...
result:
ok 246361 numbers
Test #12:
score: 0
Accepted
time: 74ms
memory: 28096kb
input:
199998 45087 90174 148909 74454 177410 88705 54750 27375 171599 85799 2112 4225 36296 72593 108 216 47854 95708 157100 78550 73947 36973 83370 41685 31408 62817 160977 80488 38130 76261 47282 94565 12540 6270 31311 62623 59838 119677 39933 19966 167722 83861 59247 118494 165805 82902 170809 85404 36...
output:
2 2 6 4 5 12 7 8 9 10 11 24 13 14 15 16 17 18 19 20 21 22 23 48 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 96 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 ...
result:
ok 200004 numbers
Test #13:
score: 0
Accepted
time: 89ms
memory: 28352kb
input:
199999 38267 77531 118682 52397 67144 104740 66906 110432 151028 105682 129211 121208 109275 135351 123149 67246 171484 191021 128996 150653 17335 35079 19439 44680 158434 13908 11401 44389 116776 15769 34186 148188 101784 62557 99681 51950 111895 129045 107684 13487 184011 3254 81869 87676 94801 55...
output:
142794 2 3 4 113163 133609 187238 8 173054 137097 3344 86175 11 48282 12 69940 14 15 122545 177533 17 102118 176231 177633 20 158094 54930 169932 22 37489 119983 81651 112306 26 27 28 89186 29 30 152837 27665 32 170871 130651 34 120931 35 149432 36 134385 37 38 1...
result:
ok 246677 numbers
Test #14:
score: 0
Accepted
time: 74ms
memory: 29072kb
input:
199997 171909 54772 131098 154342 162902 15087 12408 154697 7465 17134 71764 144746 188259 86643 149545 140097 25894 97513 104699 173697 59429 125709 14139 157055 54130 11964 8802 106868 77874 25151 37185 139746 51388 11225 13736 155459 51144 129177 157603 95825 188335 38644 43438 97154 68095 91658 ...
output:
173454 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 27159 36 37 38 39 40 41 42 43 44 45 176260 46 47 48 49 50 51 26630 52 53 54 55 56 57 58 59 60 148064 61 62 63 64 65 66 67 68 69 70...
result:
ok 208585 numbers
Test #15:
score: 0
Accepted
time: 81ms
memory: 28424kb
input:
200000 197634 198447 180741 149576 100183 170686 56004 30772 63286 37452 29775 32768 69836 123197 180904 124468 107043 136853 74303 38459 124193 30952 134737 185577 33586 47599 124288 73687 199715 161571 170939 46946 123037 36426 177585 112360 175099 56826 155818 62957 65403 24184 187437 112533 1848...
output:
89190 2 87048 3 139058 149755 5 2182 150814 8 159158 9 155336 157195 11 12 84467 112016 15 64793 149299 6353 36085 19 36534 21 99050 22 194928 24 53385 25 106957 26 27 68289 56261 93355 111666 31 10454 32 33 175158 38807 4173 36 138299 37 90182 159253 170785 39 ...
result:
ok 246484 numbers
Test #16:
score: 0
Accepted
time: 87ms
memory: 28276kb
input:
199998 80242 48326 87901 128892 193776 108384 7153 41490 125307 160392 104619 166639 32336 52260 190265 12173 24469 55111 1052 5760 3711 96380 59730 59329 20644 19135 17676 31301 134820 66508 21489 91065 171706 178094 5623 5727 105206 32857 159654 29014 42741 47900 90219 103811 18420 17205 159997 12...
output:
3 2 3 14 10 47 19 8 9 54 11 40 13 14 22 16 23 18 19 28 679 89 48 203 42 26 353 28 42 30 51 144 80 78 35 526 157 3571 54 40 58 42 43 62 62 120 54 152 49 50 78 146 385 54 382 56 210 154 59 60 320 62 295 64 624 209 641 179 29208 471 ...
result:
ok 245282 numbers
Test #17:
score: 0
Accepted
time: 104ms
memory: 53012kb
input:
199999 80526 115164 24246 187279 3921 104211 37296 150148 9575 134595 88890 68421 8203 113500 5896 159028 52780 72357 9491 123238 148008 2089 26678 76016 86193 167650 51315 87468 180910 50873 59751 178586 106149 36525 141285 118235 144030 49582 44664 87161 11536 40890 116155 159139 57089 102109 9394...
output:
38700 32408 25314 136995 38187 68020 4006 39898 170616 8393 142227 44238 84770 83909 167273 129854 9906 96033 39402 43656 140629 161707 59227 174442 50263 173006 28934 195549 61665 171711 135140 99246 155970 63774 179748 50700 140271 160141 180039 99044 121978 60257 194039...
result:
ok 299998 numbers
Test #18:
score: 0
Accepted
time: 79ms
memory: 27992kb
input:
200000 117122 183371 157946 160025 61979 157184 9285 158764 20381 143884 184479 76141 141234 189514 90809 178781 143560 59639 163743 91785 107761 54161 34746 77411 100644 123259 97075 182280 172762 47271 10155 53407 94955 77419 101111 83558 60443 142138 150836 52257 149196 69101 111656 36957 174395 ...
output:
36836 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 7...
result:
ok 200006 numbers
Test #19:
score: 0
Accepted
time: 95ms
memory: 53156kb
input:
200000 34877 186218 59365 122267 154522 76030 172513 24799 60117 80960 97655 199699 12811 63865 163557 175708 67004 130605 56291 27770 24866 136970 129524 14238 128550 80727 103008 155037 21180 14984 168297 142307 157110 142409 182804 38440 112112 170535 60033 84400 135077 35711 169021 138650 94849 ...
output:
60132 136794 142629 72735 160544 51271 10996 155740 150395 91774 198907 134551 99532 175046 189900 137353 183144 13915 139116 141715 156583 59344 81208 91495 61075 106723 138512 59005 179332 119112 10648 190182 108855 106947 24935 164093 146634 56032 86519 75117 69804 ...
result:
ok 300000 numbers
Test #20:
score: 0
Accepted
time: 96ms
memory: 44904kb
input:
199999 15501 106209 5155 157916 121379 87884 81169 41479 121058 86152 191401 130170 30281 68215 83028 15821 17024 140019 78398 113223 178291 91738 198491 153914 184518 176026 102976 131719 10143 118863 141659 31901 82690 41543 28554 147490 164471 52768 94992 199884 164930 149406 8626 40859 161651 20...
output:
3507 99708 33794 90314 132683 155973 109558 125476 66626 165265 46611 92369 142654 18523 24144 155734 90673 159349 98737 79161 157509 167133 33428 31775 57696 135529 157175 160765 176132 195253 159855 150122 48940 106526 193949 172515 2410 7215 41465 58756 37497 75189 1...
result:
ok 299997 numbers