QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#457173#8838. Jesse's Jobucup-team3510#WA 1ms5716kbC++20831b2024-06-29 08:46:402024-06-29 08:46:41

Judging History

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

  • [2024-06-29 08:46:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5716kb
  • [2024-06-29 08:46:40]
  • 提交

answer

#include <bits/stdc++.h>
#define N 1000011
using namespace std;
int t,n,a[N],id[N];bool vis[N];
vector<vector<int> > cyc;
vector<int> R;
int main()
{
	scanf("%d",&t);while(t--)
	{
		scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",a+i),id[a[i]]=i,vis[i]=0;
		cyc.clear();
		for(int i=1;i<=n;++i)if(!vis[i])
		{
			int x=i;
			cyc.push_back(vector<int>());
			while(!vis[x])vis[x]=1,cyc.back().push_back(x),x=a[x];
		}
		if(cyc.size()>=2)
		{
			printf("%d\n%d\n",n,(int)cyc[0].size());
			for(int x:cyc[0])printf("%d ",x);putchar(10);
		}
		else
		{
			printf("%d\n",n-2);
			int pt=0;
			while(cyc[0][pt]<n-1)pt=(pt+1)%n;
			pt=(pt+1)%n;
			R.clear();
			while(cyc[0][pt]<n-1)R.push_back(cyc[0][pt]),pt=(pt+1)%n;
			R.push_back(cyc[0][pt]);
			for(int x:R)printf("%d ",id[x]);putchar(10);
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5716kb

input:

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

output:

0
1 
4
2
1 2 
4
5 

result:

wrong answer Integer element pos[1] equals to 4, violates the range [1, 2] (test case 1)