QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295565#5064. DFS Orderzzuqy#AC ✓290ms9132kbC++14994b2023-12-31 13:31:282023-12-31 13:31:28

Judging History

你现在查看的是最新测评结果

  • [2023-12-31 13:31:28]
  • 评测
  • 测评结果:AC
  • 用时:290ms
  • 内存:9132kb
  • [2023-12-31 13:31:28]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for(int c=a;c<=b;++c)
#define sc(A) scanf("%d",&A)
#define go(x) for(int i=lin[x];i;i=nex[i])
using namespace std;
const int MAXN=200010;
int n;
int T,len;
int L[MAXN],R[MAXN];
int lin[MAXN],ver[MAXN],nex[MAXN],sz[MAXN];
inline void add(int x,int y)
{
	ver[++len]=y;
	nex[len]=lin[x];
	lin[x]=len;
}
void dfs(int x,int fa)
{
	sz[x]=1;
	go(x)
	{
		int tn=ver[i];
		if(tn==fa)continue;
		dfs(tn,x);
		sz[x]+=sz[tn];
	}
}
void dp(int x,int fa)
{
	go(x)
	{
		int tn=ver[i];
		if(tn==fa)continue;
		L[tn]=L[x]+1;
		R[tn]=R[x]+sz[x]-sz[tn];
		dp(tn,x);
	}
}
int main()
{
	//freopen("1.in","r",stdin);
	sc(T);
	while(T--)
	{
		sc(n);
		len=0;
		L[1]=R[1]=1;
		rep(2,n,i)
		{
			int x,y;
			sc(x);sc(y);
			add(x,y);
			add(y,x);
		}
		dfs(1,0);
		dp(1,0);
		rep(1,n,i)
		{
			printf("%d %d\n",L[i],R[i]);
			lin[i]=0;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5956kb

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: 237ms
memory: 7744kb

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: 120ms
memory: 3944kb

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: 157ms
memory: 5804kb

input:

333333
3
2 3
1 2
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2 3
3 5
2 5
3 5
1 1
2 3
3 4
2 5
4 5
1 1
2 5
3 5
2 5
2 4
1 1
3 5
2 2
3 5
3 5
1 1
3 5
2 4
2 5
2 5
1 1
2 5
2 5
2 5
2 5
1 1
4 5
2 3
3 4
2 5
1 1
3 4
2 3
2 5
4 5
1 1
2 5
2 5
2 5
2 5
1 1
2 4
2 4
3 5
3 5
1 1
3 5
3 5
2 2
3 5
...

result:

ok 2000000 numbers

Test #6:

score: 0
Accepted
time: 180ms
memory: 5984kb

input:

100000
10
1 8
4 5
7 9
2 7
1 6
1 10
1 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: 176ms
memory: 5988kb

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: 183ms
memory: 5956kb

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: 180ms
memory: 5856kb

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: 189ms
memory: 5968kb

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: 183ms
memory: 6008kb

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: 198ms
memory: 6220kb

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: 211ms
memory: 6116kb

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: 242ms
memory: 7612kb

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: 154ms
memory: 7928kb

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: 290ms
memory: 9132kb

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