QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#603917#1668. GuideUKBwyxWA 0ms3644kbC++201.0kb2024-10-01 20:59:112024-10-01 20:59:11

Judging History

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

  • [2024-10-01 20:59:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-10-01 20:59:11]
  • 提交

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) {
	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 {
			f(t);
			ans+=2;
			ans1.pb(wz);
		}
	}
	if(poi) {
		ans++;
		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<<'\n';
		for(int i=0; i<ans1.size(); i++) {
			cout<<ans1[i]<<" ";
		}
		cout<<"\n";
	}
	return 0;
}

詳細信息

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: 3644kb

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: -100
Wrong Answer
time: 0ms
memory: 3596kb

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 
15
1 2 3 2 10 2 1 7 1 4 6 8 6 4 5 9 
15
1 2 3 2 10 2 1 7 1 4 6 8 6 4 5 9 
15
1 2 3 2 10 2 1 7 1 4 6 8 6 4 5 9 
15
1 2 3 2 10 2 1 7 1 4 6 8 6 4 5 9 
15
1 2 3 2 10 2 1 7 1 4 6 8 6 4 5 9 
15
1 2 3 2 10 2 1 7 1 4 6 8 6 4 5 9 

result:

wrong answer Testcase 5. The length of the participant's path does not equal to jury's path: 15 instead of 5