/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 532.0 KiB
#2 Wrong Answer 122ms 2.457 MiB

Code

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

struct DSU {
    vector<int> par, rank, sz;
    int c;
    DSU(int n) : par(n + 1), rank(n + 1, 0), sz(n + 1, 1), c(n) {
        for (int i = 1; i <= n; i++) par[i] = i;
    }
    int find(int v) {
        if (par[v] == v) return v;
        else return par[v] = find(par[v]); 
    }
    bool same(int a, int b) {
        return find(a) == find(b);
    }
    int get_size(int v) {
        return sz[find(v)];
    }
    int count() {
        return c;
    }
    void merge(int a, int b) {
        a = find(a), b = find(b);
        if (a == b) return; 
        c--; 
        if (rank[a] > rank[b]) swap(a, b);
        par[a] = b;
        sz[b] += sz[a];
        if (rank[a] == rank[b]) rank[b]++;
    }
};

int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--){
        int n, q, s = 0;
        cin >> n >> q;
        vector<int> a(n+1),vis(n+1);
        for (int i = 1; i <= n; i++){
            cin >> a[i];
            if (i == a[i]) vis[i] = 1;
        }
        DSU dsu(n + 1);
        while (q--){
            int x, y;
            cin >> x >> y;
            if (vis[x]||vis[y]) continue;
            if (a[x]==y||a[y]==x){
                vis[x]=vis[y]=1;
            }
        }
        int mx = 0;
        for (int i = 1; i <= n; i++){
            s += vis[i];
        }
        cout << s<<endl;
    }
}

Information

Submit By
Type
Submission
Problem
P1119 Maximizing Fixed Points
Contest
Happy New Year 2025
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-02 16:58:24
Judged At
2025-01-02 16:58:24
Judged By
Score
0
Total Time
122ms
Peak Memory
2.457 MiB