/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 141ms 2.066 MiB
#3 Wrong Answer 47ms 1.98 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;
        cin >> n >> q;
        vector<int> a(n+1);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        DSU dsu(n + 1);
        while (q--){
            int x, y;
            cin >> x >> y;
            dsu.merge(a[x - 1], a[y - 1]);
        }
        int mx = 0;
        for (int i = 1; i <= n; i++){
            mx = max(mx, dsu.get_size(i));
        }
        cout << mx << 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:59:20
Judged At
2025-01-02 16:59:20
Judged By
Score
5
Total Time
141ms
Peak Memory
2.066 MiB