QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#626794 | #5064. DFS Order | pengpeng_fudan# | AC ✓ | 333ms | 15016kb | C++23 | 808b | 2024-10-10 13:06:40 | 2024-10-10 13:06:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin>>n;
vector<vector<int>> tr(n+1);
for(int i=1;i<=n-1;i++){
int u,v;
cin>>u>>v;
tr[u].push_back(v);
tr[v].push_back(u);
}
vector<pair<int,int>> ans(n+1);
auto dfs=[&](auto self,int u,int v,int dp)->int {
ans[u].first=dp+1;
int siz=1;
for(auto i:tr[u]){
if(i==v) continue;
siz+=self(self,i,u,dp+1);
}
ans[u].second=n-siz+1;
return siz;
};
dfs(dfs,1,1,0);
for(int i=1;i<=n;i++){
cout<<ans[i].first<<' '<<ans[i].second<<'\n';
}
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
int _ =1;
cin>>_;
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
2 4 1 2 2 3 3 4 5 1 2 2 3 2 4 1 5
output:
1 1 2 2 3 3 4 4 1 1 2 3 3 5 3 5 2 5
result:
ok 18 numbers
Test #2:
score: 0
Accepted
time: 333ms
memory: 9868kb
input:
10 100000 72823 55259 62351 52308 92651 3592 51367 76912 79245 19657 42249 51964 79361 189 27637 93873 81277 28980 74091 19175 36499 5372 4007 43408 80222 240 58323 89130 7186 75148 68314 35801 714 47923 93849 84391 67266 14569 33233 68208 4770 53070 57228 93090 80479 13476 78786 23062 27420 80196 1...
output:
1 1 11 100000 12 100000 17 99998 18 99999 10 99998 10 99999 22 100000 14 100000 10 99995 14 99999 13 99998 10 99981 12 99998 10 99998 12 100000 10 100000 15 100000 17 99999 17 99995 11 100000 19 99997 15 99999 13 99991 8 99999 13 100000 21 99993 11 99993 16 100000 16 100000 12 100000 14 99974 10 999...
result:
ok 2000000 numbers
Test #3:
score: 0
Accepted
time: 125ms
memory: 3568kb
input:
1000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 2000000 numbers
Test #4:
score: 0
Accepted
time: 151ms
memory: 3784kb
input:
333333 3 2 3 1 2 3 1 2 2 3 3 1 3 1 2 3 1 2 1 3 3 1 2 2 3 3 1 3 3 2 3 1 2 2 3 3 2 3 1 2 3 1 3 1 2 3 3 2 1 3 3 1 3 3 2 3 1 3 1 2 3 1 2 1 3 3 1 2 1 3 3 1 2 2 3 3 1 3 3 2 3 1 2 1 3 3 1 2 2 3 3 3 2 1 3 3 1 2 2 3 3 1 2 1 3 3 1 3 3 2 3 1 3 1 2 3 2 3 1 2 3 1 2 1 3 3 1 3 1 2 3 1 2 1 3 3 2 3 1 2 3 1 2 1 3 3 2...
output:
1 1 2 2 3 3 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2 6 3 10 4 10 1 8 1 7 4 3 4 10 1 2 1 4 3 6 7 9 8 5 10 1 4 2 10 1 7 9 8 2 9 1 6 1 2 6 5 5 3 10 3 8 1 10 1 4 10 7 3 6 4 5 10 9 1 2 1 3 10 2 10 1 7 6 4 7 5 3 8 1 3 6 2 1 6 3 9 10 5 4 4 8 1 6 6 10 1 7 3 9 5 3 1 5 4 2 10 9 6 1 2 7 5 1 9 9 3 7 4 10 7 5 8 9 10 10 8 6 1 ...
output:
1 1 2 8 3 10 3 9 4 10 2 9 3 9 2 10 4 10 2 8 1 1 2 10 3 9 2 7 3 10 4 10 2 9 2 9 3 10 3 10 1 1 2 7 4 10 2 10 3 9 2 8 2 10 4 10 3 9 3 10 1 1 2 10 2 8 2 9 3 10 3 10 3 10 3 10 3 10 2 8 1 1 3 9 2 8 3 10 3 10 2 7 2 9 3 10 3 10 4 10 1 1 4 10 3 9 3 8 2 5 2 9 2 10 4 10 4 10 3 10 1 1 2 10 3 10 5 10 5 9 3 10 4 ...
result:
ok 2000000 numbers
Test #7:
score: 0
Accepted
time: 182ms
memory: 3572kb
input:
100000 10 4 9 7 8 1 7 7 2 7 5 5 4 9 10 5 6 2 3 10 1 8 4 10 1 7 6 2 1 4 9 3 1 9 7 6 1 5 10 7 5 4 2 4 9 8 3 4 8 3 6 5 10 1 7 7 4 10 5 2 6 7 9 4 3 10 1 8 10 9 8 3 1 5 1 6 10 10 8 2 9 9 3 9 7 4 5 4 2 6 4 1 10 1 6 10 6 5 1 2 6 10 2 6 9 8 2 4 10 7 2 3 2 9 10 1 6 2 10 1 7 5 9 8 5 7 8 5 2 10 3 1 4 10 6 9 1 ...
output:
1 1 3 9 4 10 4 8 3 6 4 10 2 2 3 10 5 9 6 10 1 1 4 10 3 10 2 9 2 10 3 9 2 8 2 10 2 9 3 10 1 1 4 10 5 9 3 5 3 9 6 10 2 2 4 8 4 10 4 10 1 1 3 10 3 7 6 10 2 9 2 9 3 10 2 6 5 9 4 8 1 1 4 7 6 10 3 5 4 10 2 4 6 10 3 10 5 8 2 9 1 1 2 2 3 10 3 10 4 10 3 7 5 10 4 10 3 9 4 9 1 1 5 8 7 10 2 10 4 6 2 10 2 4 3 5 ...
result:
ok 2000000 numbers
Test #8:
score: 0
Accepted
time: 217ms
memory: 3624kb
input:
10000 100 82 7 73 27 1 3 88 71 91 34 88 61 59 62 73 12 5 89 91 2 18 45 54 73 81 82 96 48 79 41 33 86 95 52 26 83 10 36 46 6 20 35 16 97 85 96 13 77 30 58 64 95 99 5 32 60 88 75 61 26 6 24 30 8 12 51 19 63 46 80 73 56 25 40 84 28 18 15 72 4 99 39 18 68 16 21 1 90 13 25 61 54 4 32 1 91 4 81 21 70 39 1...
output:
1 1 3 100 2 97 6 79 3 96 4 95 9 100 8 94 8 100 3 99 4 100 7 98 2 87 8 100 5 100 3 96 4 100 4 97 4 97 8 98 4 99 8 100 3 99 5 96 3 98 5 93 7 100 3 100 9 100 7 90 4 100 7 98 3 92 3 100 9 100 4 100 6 100 5 100 3 72 4 100 5 100 6 100 7 100 5 100 5 100 3 92 9 100 8 100 8 100 7 100 8 100 11 99 8 100 5 94 3...
result:
ok 2000000 numbers
Test #9:
score: 0
Accepted
time: 217ms
memory: 3572kb
input:
10000 100 20 95 66 16 43 8 83 94 82 14 3 33 1 63 6 34 20 76 43 73 78 82 76 48 93 41 77 26 55 90 80 93 80 47 50 78 77 91 36 89 45 12 48 77 27 28 65 18 1 58 1 45 47 50 97 62 31 100 38 31 31 66 38 80 21 65 80 21 78 85 76 98 69 44 9 56 75 83 26 84 15 11 1 38 100 75 7 35 24 27 66 97 20 87 86 42 72 25 31 ...
output:
1 1 6 99 2 98 3 100 5 97 5 99 5 99 3 100 6 99 7 99 3 100 3 99 4 100 8 98 2 99 5 100 2 99 6 100 8 100 3 78 4 97 5 100 9 100 4 98 5 100 7 99 5 99 6 100 3 97 8 99 3 78 4 100 3 100 6 100 6 100 5 99 3 100 2 23 7 100 5 99 5 100 8 100 2 97 6 96 2 94 7 99 4 83 5 91 6 98 5 86 8 100 7 99 3 97 6 100 6 99 7 100...
result:
ok 2000000 numbers
Test #10:
score: 0
Accepted
time: 250ms
memory: 3684kb
input:
1000 1000 674 950 98 379 526 638 362 786 366 278 689 297 488 141 73 350 854 752 901 263 993 105 237 694 546 814 857 702 551 86 742 462 124 147 18 443 504 731 447 149 682 635 475 261 378 603 789 894 743 466 632 624 960 867 926 712 32 877 532 157 179 720 799 186 808 750 219 31 230 129 507 500 266 190 ...
output:
1 1 9 999 8 1000 7 1000 6 1000 7 990 5 999 4 993 9 997 6 999 9 1000 9 1000 6 974 5 1000 10 999 8 999 7 1000 4 999 6 999 5 990 8 998 7 985 5 1000 5 992 9 996 10 1000 5 996 9 1000 6 997 7 995 5 1000 7 995 6 999 4 998 11 1000 7 997 6 1000 6 994 5 1000 7 1000 6 1000 4 897 9 997 7 1000 6 1000 7 1000 6 10...
result:
ok 2000000 numbers
Test #11:
score: 0
Accepted
time: 221ms
memory: 3620kb
input:
1000 1000 270 866 414 238 362 247 716 776 264 509 626 138 3 511 947 981 491 849 598 489 730 79 247 877 748 13 265 1000 982 384 826 98 275 202 212 913 598 488 963 68 616 386 676 611 52 743 492 788 676 391 386 444 940 450 743 737 354 863 21 942 646 383 794 633 199 641 516 822 236 275 533 454 505 678 1...
output:
1 1 9 1000 8 980 9 1000 9 999 7 999 11 997 9 999 8 1000 8 999 7 995 3 999 5 995 6 1000 6 1000 5 992 7 986 11 1000 9 994 4 1000 4 998 7 999 10 1000 10 990 9 1000 9 999 7 1000 5 997 8 999 10 1000 8 1000 8 999 5 990 6 997 7 996 6 985 7 1000 10 1000 7 999 8 998 12 999 8 995 9 1000 3 999 9 999 7 1000 6 1...
result:
ok 2000000 numbers
Test #12:
score: 0
Accepted
time: 230ms
memory: 4232kb
input:
100 10000 630 779 8192 918 416 9581 2495 9929 9419 1368 2249 3050 4382 1416 1030 955 7636 1286 6853 2542 2451 4086 4775 3489 2501 6116 4855 4254 7856 9816 5742 2176 920 9198 7557 233 5356 4387 7424 3450 6445 552 5992 6525 8405 3225 8173 9367 6721 609 8528 1770 8428 9822 9850 5104 7444 3484 9497 8844...
output:
1 1 12 9999 10 9997 11 10000 15 9999 13 9998 14 10000 9 10000 11 10000 7 9983 7 10000 11 9999 8 9997 10 10000 13 10000 12 9999 10 10000 16 10000 12 10000 6 9989 9 9979 11 10000 9 10000 10 9985 15 9999 9 9999 8 9999 9 10000 12 10000 10 9987 10 10000 11 10000 11 10000 6 10000 9 10000 17 10000 9 10000 ...
result:
ok 2000000 numbers
Test #13:
score: 0
Accepted
time: 239ms
memory: 4200kb
input:
100 10000 6711 399 6883 7611 6759 2649 9617 8653 2616 4450 5846 9830 9807 4371 3796 1417 4814 610 2308 7018 3573 9037 6664 6594 9435 7938 5519 203 67 1306 2045 4975 202 4943 1627 1309 8401 9898 5436 8415 2405 4618 2505 2830 3232 9436 4181 4511 8640 4501 4001 7743 1388 1539 7683 2567 4615 4482 580 84...
output:
1 1 10 9999 8 9999 12 9998 9 9998 10 10000 6 9999 8 9995 6 9999 11 9998 9 9999 9 9999 11 10000 11 10000 7 10000 8 9998 10 10000 8 10000 9 10000 10 10000 11 9998 13 10000 7 10000 8 10000 4 9981 11 10000 7 9999 13 10000 8 9999 7 10000 10 9989 9 10000 11 10000 13 9996 7 10000 10 9999 12 10000 8 9998 8 ...
result:
ok 2000000 numbers
Test #14:
score: 0
Accepted
time: 300ms
memory: 9984kb
input:
10 100000 11761 19532 78117 62093 9660 33693 73707 72221 98402 72735 29356 81444 58870 8339 24727 106 29493 71436 37542 98525 72256 76183 8113 24913 41886 69802 55069 43006 80322 14664 6929 52747 8081 80038 34943 72217 12940 49558 9716 58641 41935 64730 41696 37730 90867 80822 6036 46161 22315 40228...
output:
1 1 13 100000 18 100000 14 99998 12 100000 12 100000 14 99996 19 100000 7 99998 13 99997 13 100000 9 99999 17 100000 12 99996 10 99948 5 99996 11 100000 13 99998 11 99999 14 99999 12 99998 10 99999 13 100000 16 99999 11 100000 13 100000 9 99989 10 99998 18 100000 11 100000 12 100000 12 99996 11 9999...
result:
ok 2000000 numbers
Test #15:
score: 0
Accepted
time: 169ms
memory: 3552kb
input:
100000 10 4 2 2 3 1 7 8 6 9 10 6 5 3 8 7 9 10 4 10 10 3 1 5 8 6 2 4 9 10 4 7 7 8 6 9 5 2 10 4 8 10 7 1 9 3 10 6 5 5 4 9 3 7 2 2 6 10 9 8 2 3 5 10 6 9 10 7 4 6 1 5 8 2 7 4 10 2 5 6 7 8 9 3 10 9 4 10 6 4 3 1 8 7 2 10 3 6 6 9 7 4 1 3 9 8 10 5 5 2 8 7 4 10 10 8 10 10 2 6 7 1 8 5 3 7 9 4 5 2 6 9 4 10 10 ...
output:
1 1 6 6 7 7 5 5 10 10 9 9 2 2 8 8 3 3 4 4 1 1 3 3 10 10 4 4 2 2 7 7 5 5 6 6 8 8 9 9 1 1 6 6 3 3 9 9 8 8 7 7 5 5 10 10 2 2 4 4 1 1 9 9 10 10 5 5 2 2 6 6 4 4 8 8 7 7 3 3 1 1 9 9 5 5 4 4 10 10 7 7 8 8 2 2 3 3 6 6 1 1 10 10 2 2 7 7 9 9 3 3 6 6 5 5 4 4 8 8 1 1 4 4 10 10 8 8 9 9 5 5 6 6 2 2 7 7 3 3 1 1 5 ...
result:
ok 2000000 numbers
Test #16:
score: 0
Accepted
time: 312ms
memory: 15016kb
input:
10 100000 32590 1363 71087 72550 44633 77577 94603 64819 24465 19318 46377 45542 40699 20825 30041 83274 60470 74807 31172 84501 74027 5738 27104 97141 56855 71820 83973 38419 51290 10659 17079 93607 83129 3056 36995 26966 5090 33678 62260 86126 91704 48970 75963 58464 50216 93111 23483 40943 36026 ...
output:
1 1 70680 70680 33947 33947 76850 76850 89265 89265 64336 64336 3592 3592 10317 10317 25849 25849 98342 98342 32639 32639 12705 12705 90027 90027 65718 65718 6816 6816 95212 95212 57238 57238 47979 47979 9404 9404 40917 40917 13622 13622 10760 10760 39981 39981 14970 14970 98425 98425 98780 98780 16...
result:
ok 2000000 numbers