QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#459225 | #8838. Jesse's Job | ucup-team1134# | WA | 0ms | 3644kb | C++23 | 1.3kb | 2024-06-29 23:45:47 | 2024-06-29 23:45:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;
void solve(){
int N;cin>>N;
vector<int> P(N),seen(N);
for(int i=0;i<N;i++){
cin>>P[i];P[i]--;
}
vector<vector<int>> ans;
for(int i=0;i<N;i++){
if(seen[i]) continue;
ans.push_back({});
int now=i;
while(1){
if(seen[now]) break;
seen[now]=true;
ans.back().push_back(now);
now=P[now];
}
}
if(si(ans)>=2){
cout<<N<<"\n";
cout<<si(ans[0])<<"\n";
for(int x:ans[0]) cout<<x+1<<" ";
cout<<"\n";
}else{
cout<<N-2<<"\n";
cout<<1<<"\n";
cout<<ans[0][0]+1<<"\n";
}
}
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int Q;cin>>Q;
while(Q--){
solve();
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3644kb
input:
3 2 2 1 4 2 1 4 3 6 3 5 4 2 6 1
output:
0 1 1 4 2 1 2 4 1 1
result:
wrong answer Participant didn't find permutation (test case 3)