QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#603933#1668. GuideUKBwyxWA 1ms3720kbC++201.0kb2024-10-01 21:05:102024-10-01 21:05:10

Judging History

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

  • [2024-10-01 21:05:10]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3720kb
  • [2024-10-01 21:05:10]
  • 提交

answer

#include<bits/stdc++.h>
#define pii pair<long long,long long>
#define mp make_pair
#define pb push_back
using namespace std;
long long t,n,dp[105],p[105],ans=0,k,w1;
vector<long long>ljb[105],ans1;
pii ed;
bool b[105];
void f(int wz) {
	ans++;
	ans1.pb(wz);
	long long poi=0;
	for(int i=0; i<ljb[wz].size(); i++) {
		int t=ljb[wz][i];
		if(dp[t]>k||k<=w1&&!b[t])continue;
		if(b[t])poi=t;
		else {
			k--;
			f(t);
			ans++;
			ans1.pb(wz);
		}
	}
	if(poi) {
		f(poi);
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--) {
		cin>>n>>k;
		ed=mp(0,1);
		ans1.clear();
		for(int i=1; i<=n; i++) {
			ljb[i].clear();
		}
		dp[1]=1;
		ans=0;
		for(int i=2; i<=n; i++) {
			cin>>p[i];
			dp[i]=dp[p[i]]+1;
			ed=max(ed,mp(dp[i],i+0ll));
			ljb[p[i]].pb(i);
		}
		w1=ed.first;
		long long wz=ed.second;
		while(wz) {
			b[wz]=1;
			wz=p[wz];
		}
		f(1);
		cout<<ans-1<<'\n';
		for(int i=0; i<ans1.size(); i++) {
			cout<<ans1[i]<<" ";
		}
		cout<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

3
6 2
1 1 2 2 3
6 6
1 1 2 2 3
6 4
1 2 3 4 5

output:

1
1 3 
8
1 2 4 2 5 2 1 3 6 
3
1 2 3 4 

result:

ok All testcases are passed!

Test #2:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

3
1 1

2 1
1
2 2
1

output:

0
1 
0
1 
1
1 2 

result:

ok All testcases are passed!

Test #3:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

10
10 1
1 2 1 4 4 1 6 5 2
10 2
1 2 1 4 4 1 6 5 2
10 3
1 2 1 4 4 1 6 5 2
10 4
1 2 1 4 4 1 6 5 2
10 5
1 2 1 4 4 1 6 5 2
10 6
1 2 1 4 4 1 6 5 2
10 7
1 2 1 4 4 1 6 5 2
10 8
1 2 1 4 4 1 6 5 2
10 9
1 2 1 4 4 1 6 5 2
10 10
1 2 1 4 4 1 6 5 2

output:

0
1 
1
1 4 
2
1 4 5 
3
1 4 5 9 
5
1 2 1 4 5 9 
7
1 2 3 2 1 4 5 9 
9
1 2 3 2 10 2 1 4 5 9 
11
1 2 3 2 10 2 1 7 1 4 5 9 
13
1 2 3 2 10 2 1 7 1 4 6 4 5 9 
15
1 2 3 2 10 2 1 7 1 4 6 8 6 4 5 9 

result:

ok All testcases are passed!

Test #4:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

100
100 1
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50
100 2
1 1 2...

output:

0
1 
1
1 3 
2
1 3 6 
3
1 3 6 12 
4
1 3 6 12 25 
5
1 3 6 12 25 50 
6
1 3 6 12 25 50 100 
8
1 2 1 3 6 12 25 50 100 
10
1 2 4 2 1 3 6 12 25 50 100 
12
1 2 4 8 4 2 1 3 6 12 25 50 100 
14
1 2 4 8 16 8 4 2 1 3 6 12 25 50 100 
16
1 2 4 8 16 32 16 8 4 2 1 3 6 12 25 50 100 
18
1 2 4 8 16 32 64 32 16 8 4 2 1 ...

result:

ok All testcases are passed!

Test #5:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

100
100 1
1 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
10...

output:

0
1 
1
1 2 
2
1 2 3 
3
1 2 3 4 
4
1 2 3 4 5 
5
1 2 3 4 5 6 
6
1 2 3 4 5 6 7 
7
1 2 3 4 5 6 7 8 
8
1 2 3 4 5 6 7 8 9 
9
1 2 3 4 5 6 7 8 9 10 
10
1 2 3 4 5 6 7 8 9 10 11 
11
1 2 3 4 5 6 7 8 9 10 11 12 
12
1 2 3 4 5 6 7 8 9 10 11 12 13 
13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 
14
1 2 3 4 5 6 7 8 9 10 11 12...

result:

ok All testcases are passed!

Test #6:

score: 0
Accepted
time: 1ms
memory: 3648kb

input:

100
100 1
1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 61 61 63 63 65 65 67 67 69 69 71 71 73 73 75 75 77 77 79 79 81 81 83 83 85 85 87 87 89 89 91 91 93 93 95 95 97 97 99
100...

output:

0
1 
1
1 3 
2
1 3 5 
3
1 3 5 7 
4
1 3 5 7 9 
5
1 3 5 7 9 11 
6
1 3 5 7 9 11 13 
7
1 3 5 7 9 11 13 15 
8
1 3 5 7 9 11 13 15 17 
9
1 3 5 7 9 11 13 15 17 19 
10
1 3 5 7 9 11 13 15 17 19 21 
11
1 3 5 7 9 11 13 15 17 19 21 23 
12
1 3 5 7 9 11 13 15 17 19 21 23 25 
13
1 3 5 7 9 11 13 15 17 19 21 23 25 27 ...

result:

ok All testcases are passed!

Test #7:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

100
100 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
100 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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:

0
1 
1
1 100 
3
1 2 1 100 
5
1 2 1 3 1 100 
7
1 2 1 3 1 4 1 100 
9
1 2 1 3 1 4 1 5 1 100 
11
1 2 1 3 1 4 1 5 1 6 1 100 
13
1 2 1 3 1 4 1 5 1 6 1 7 1 100 
15
1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 100 
17
1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 100 
19
1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 100 
21
1 2 1 3 1 4 1 5 ...

result:

ok All testcases are passed!

Test #8:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

100
100 1
1 2 2 1 3 3 5 4 3 1 5 3 4 2 14 9 10 8 11 16 7 6 6 5 5 24 23 6 28 30 11 24 8 2 19 26 29 37 23 33 19 37 19 44 30 19 44 44 40 37 22 41 44 26 31 53 8 51 15 3 17 47 63 21 8 62 43 9 49 38 48 49 34 47 44 29 66 1 39 26 16 31 72 41 48 77 8 74 8 67 12 2 24 75 91 36 8 23 69
100 2
1 2 2 1 3 3 5 4 3 1 ...

output:

0
1 
1
1 2 
2
1 2 4 
3
1 2 4 9 
4
1 2 4 9 17 
5
1 2 4 9 17 62 
6
1 2 4 9 17 62 67 
7
1 2 4 9 17 62 67 91 
8
1 2 4 9 17 62 67 91 96 
10
1 5 1 2 4 9 17 62 67 91 96 
12
1 5 8 5 1 2 4 9 17 62 67 91 96 
14
1 5 8 19 8 5 1 2 4 9 17 62 67 91 96 
16
1 5 8 19 36 19 8 5 1 2 4 9 17 62 67 91 96 
18
1 5 8 19 36 9...

result:

ok All testcases are passed!

Test #9:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

100
100 1
1 1 2 4 5 4 2 8 8 4 9 11 9 5 6 2 2 3 6 5 8 1 23 5 2 15 13 13 17 8 15 24 13 25 6 3 9 22 34 32 23 39 7 39 30 44 28 36 16 34 50 45 48 2 14 23 21 37 57 39 9 14 20 42 10 22 12 49 34 40 17 69 48 74 15 8 47 14 39 43 1 60 50 3 5 32 87 79 68 7 2 65 27 67 72 26 29 86 59
100 2
1 1 2 4 5 4 2 8 8 4 9 1...

output:

0
1 
1
1 2 
2
1 2 4 
3
1 2 4 11 
4
1 2 4 11 13 
5
1 2 4 11 13 28 
6
1 2 4 11 13 28 48 
7
1 2 4 11 13 28 48 74 
8
1 2 4 11 13 28 48 74 75 
10
1 3 1 2 4 11 13 28 48 74 75 
12
1 3 19 3 1 2 4 11 13 28 48 74 75 
14
1 3 19 3 37 3 1 2 4 11 13 28 48 74 75 
16
1 3 19 3 37 59 37 3 1 2 4 11 13 28 48 74 75 
18
...

result:

ok All testcases are passed!

Test #10:

score: 0
Accepted
time: 0ms
memory: 3720kb

input:

100
100 1
1 1 1 2 2 5 7 3 4 5 7 12 4 9 1 7 11 2 4 19 6 22 5 21 11 12 6 3 9 21 2 22 28 25 23 20 31 7 28 34 13 32 8 5 44 8 24 43 39 44 42 34 36 6 37 42 54 13 46 49 27 51 24 42 2 13 37 66 66 59 7 65 4 14 27 28 26 52 68 25 61 51 40 31 49 64 42 40 44 8 33 22 13 38 32 88 62 93 88
100 2
1 1 1 2 2 5 7 3 4 5...

output:

0
1 
1
1 2 
2
1 2 5 
3
1 2 5 7 
4
1 2 5 7 12 
5
1 2 5 7 12 13 
6
1 2 5 7 12 13 42 
7
1 2 5 7 12 13 42 88 
8
1 2 5 7 12 13 42 88 100 
10
1 3 1 2 5 7 12 13 42 88 100 
12
1 3 9 3 1 2 5 7 12 13 42 88 100 
14
1 3 9 15 9 3 1 2 5 7 12 13 42 88 100 
16
1 3 9 15 9 30 9 3 1 2 5 7 12 13 42 88 100 
18
1 3 9 15 ...

result:

ok All testcases are passed!

Test #11:

score: 0
Accepted
time: 1ms
memory: 3564kb

input:

100
100 1
1 2 1 1 4 4 5 8 7 8 10 7 11 12 8 16 2 14 17 7 6 14 5 5 8 5 23 11 19 30 7 23 3 14 10 33 11 30 39 33 15 34 39 24 37 33 34 35 15 39 19 37 40 51 7 12 10 57 29 26 22 18 44 63 4 37 6 38 23 48 47 13 19 41 73 67 8 65 14 42 47 1 15 78 48 27 25 45 15 37 23 32 18 57 14 14 83 58 78
100 2
1 2 1 1 4 4 5...

output:

0
1 
1
1 5 
2
1 5 8 
3
1 5 8 11 
4
1 5 8 11 14 
5
1 5 8 11 14 23 
6
1 5 8 11 14 23 33 
7
1 5 8 11 14 23 33 37 
8
1 5 8 11 14 23 33 37 67 
9
1 5 8 11 14 23 33 37 67 77 
11
1 2 1 5 8 11 14 23 33 37 67 77 
13
1 2 3 2 1 5 8 11 14 23 33 37 67 77 
15
1 2 3 34 3 2 1 5 8 11 14 23 33 37 67 77 
17
1 2 3 34 43...

result:

ok All testcases are passed!

Test #12:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

100
100 1
1 1 2 1 5 2 5 5 9 2 10 9 1 14 11 14 10 6 8 4 11 1 2 14 17 17 3 7 24 18 29 26 32 17 25 21 23 37 12 39 33 4 7 8 8 28 11 45 38 25 7 29 29 52 46 3 29 10 6 22 53 40 14 41 19 32 55 33 42 8 58 16 35 59 4 64 66 3 9 29 7 69 60 60 4 1 37 5 3 6 7 67 44 2 17 60 28 79 31
100 2
1 1 2 1 5 2 5 5 9 2 10 9 ...

output:

0
1 
1
1 2 
2
1 2 4 
3
1 2 4 21 
4
1 2 4 21 37 
5
1 2 4 21 37 39 
6
1 2 4 21 37 39 41 
7
1 2 4 21 37 39 41 65 
9
1 3 1 2 4 21 37 39 41 65 
11
1 3 28 3 1 2 4 21 37 39 41 65 
13
1 3 28 47 28 3 1 2 4 21 37 39 41 65 
15
1 3 28 47 28 98 28 3 1 2 4 21 37 39 41 65 
17
1 3 28 47 28 98 28 3 57 3 1 2 4 21 37 ...

result:

ok All testcases are passed!

Test #13:

score: -100
Wrong Answer
time: 1ms
memory: 3568kb

input:

100
100 34
1 1 3 1 4 3 3 2 5 5 3 1 6 4 3 7 1 18 2 5 12 15 2 14 16 10 20 15 12 26 3 27 5 6 35 14 26 6 35 39 37 6 38 27 8 7 21 38 14 22 35 33 33 43 16 29 26 4 47 59 47 7 34 62 21 56 24 13 28 10 28 36 50 64 50 26 48 17 34 46 57 17 34 22 46 50 20 10 85 35 88 38 49 88 94 82 50 44 21
100 74
1 1 2 3 3 6 7 ...

output:

59
1 2 9 2 20 28 70 28 72 28 20 88 92 88 95 88 20 2 24 68 24 2 1 5 10 27 33 53 33 54 33 27 45 27 10 71 10 89 10 5 11 5 21 48 78 48 21 66 21 100 21 5 1 3 4 15 29 57 82 97 
141
1 2 9 16 35 16 9 64 85 64 9 65 86 65 9 15 2 27 50 27 2 4 98 4 1 41 53 91 53 41 1 3 5 42 52 95 52 42 96 42 5 45 5 3 46 3 61 66...

result:

wrong answer Testcase 2. The length of the participant's path does not equal to jury's path: 141 instead of 136