QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#457840 | #8838. Jesse's Job | ucup-team1525# | WA | 1ms | 3720kb | C++20 | 1.2kb | 2024-06-29 14:23:30 | 2024-06-29 14:23:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int t;
int n;
const int N=1000005;
int a[N];
vector<int> v;
void dfs(int x)
{
v.push_back(x);
if (a[x]!=1)
dfs(a[x]);
}
int main()
{
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
for (int i=1;i<=n;++i)
scanf("%d",&a[i]);
v.clear();
dfs(1);
if (v.size()!=n)
{
printf("%d\n%d\n",n,(int)v.size());
sort(v.begin(),v.end());
for (int x:v)
printf("%d ",x);
puts("");
}
else
{
for (int i=1;i<n;++i)
if (v[i]==2)
{
printf("%d\n%d\n",n-2,i);
for (int j=0;j<i;++j)
printf("%d ",v[i]);
puts("");
break;
}
// int mnp=1;
// for (int i=2;i<=n;++i)
// if (abs(mnp-a[mnp])>abs(i-a[i]))
// mnp=i;
// int ans=n-abs(mnp-a[mnp])-1;
// printf("%d\n1\n%d\n",ans,mnp);
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3720kb
input:
3 2 2 1 4 2 1 4 3 6 3 5 4 2 6 1
output:
0 1 2 4 2 1 2 4 3 2 2 2
result:
wrong answer Participant didn't find permutation (test case 3)