QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#505794#8838. Jesse's JobxiaogongkeainieWA 0ms3752kbC++201.6kb2024-08-05 11:32:422024-08-05 11:32:43

Judging History

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

  • [2024-08-05 11:32:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3752kb
  • [2024-08-05 11:32:42]
  • 提交

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)