QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#505794 | #8838. Jesse's Job | xiaogongkeainie | WA | 0ms | 3752kb | C++20 | 1.6kb | 2024-08-05 11:32:42 | 2024-08-05 11:32:43 |
Judging History
answer
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define int long long
#define endl '\n'
#define enld '\n'
void solve() {
int n;
cin >> n;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
int cnt = 0;
vector<int> huan(n + 1);
vector<bool> vis(n + 1);
vector<int> size_huan;
for (int i = 1; i <= n; i++) {
if(vis[i])
continue;
int temp_size = 1;
int son = v[i];
vis[i] = true;
huan[i] = cnt;
while(!vis[son]) {
temp_size++;
vis[son] = true;
huan[son] = cnt;
son = v[son];
}
size_huan.push_back(temp_size);
cnt++;
}
if(cnt == 1) {
cout << n - 2 << endl;
if(n == 2) {
cout << 1 << endl;
cout << 1 << endl;
}
else {
cout << 2 << endl;
int pos_1 = 0;
for (int i = 1; i <= n; i++) {
if(v[i] == 1) {
pos_1 = i;
break;
}
}
cout << 1 << " " << pos_1 << endl;
}
return;
}
cout << n << endl;
cout << size_huan[0] << enld;
vector<int> ans;
for (int i = 1; i <= n; i++) {
if(huan[i] == 0)
ans.push_back(i);
}
for(auto i : ans) {
cout << i << " ";
}
cout << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3752kb
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 2 1 6
result:
wrong answer Participant didn't find permutation (test case 3)