QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#603424 | #8838. Jesse's Job | szcqwq | WA | 1ms | 5964kb | C++14 | 1.0kb | 2024-10-01 16:30:43 | 2024-10-01 16:30:44 |
Judging History
answer
#include <bits/stdc++.h>
//#include <windows.h>
#define ED cerr<<endl;
#define TS cerr<<"I AK IOI"<<endl;
#define cr(x) cerr<<x<<endl;
#define cr2(x,y) cerr<<x<<" "<<y<<endl;
#define cr3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<endl;
#define cr4(x,y,z,w) cerr<<x<<" "<<y<<" "<<z<<" "<<w<<endl;
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
#define ll long long
//#define ull unsigned long long
using namespace std;
const int N=1e6+5,INF=2e9,mod=1e9+7;
int t,n,m;
int ne[N],vis[N];
vector<int> s;
void sol() {
scanf("%d",&n);
for(int i=1;i<=n;++i) {
scanf("%d",&ne[i]);
}
int cnt=0;
for(int i=1;i<=n;++i) {
if(!vis[i]) {
int p=i;++cnt;
s.clear();
while(!vis[p]) {
s.emplace_back(p);
vis[p]=1,p=ne[p];
}
}
}
if(cnt==2) {
printf("%d\n",s.size());
for(auto it:s) printf("%d ",it);
}
else {
printf("%d\n",n-1);
for(int i=1;i<=n-1;++i) printf("%d ",i);
}
puts("");
}
int main()
{
scanf("%d",&t);
while(t--) {
sol();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5964kb
input:
3 2 2 1 4 2 1 4 3 6 3 5 4 2 6 1
output:
1 1 3 1 2 3 5 1 2 3 4 5
result:
wrong answer Integer element pos[1] equals to 3, violates the range [1, 2] (test case 1)