Submission #3954319


Source Code Expand

//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

class UnionFind {
    private:
        vi par;    // x の親ノード
        vi rank;   // 木の高さ
        vi mem;    // メンバの数
        int sz;             // 集合の個数
    public:
        UnionFind(int n) :
            par(n, -1), rank(n, 0), mem(n, 1), sz(n) {
            REP(i,n) par[i] = i;
        }
    
    int size() { return sz; }

    // 集合の追加
    void makeset() {
        par.pb(par.size());
        rank.pb(0);
        mem.pb(1);
        sz++;
    }

    int find(int x) {
        if (par[x] == x)
            return x;
        else
            return par[x] = find(par[x]);
    }

    int member(int x){
        x = find(x);
        return mem[x];
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y]){
            par[x] = y;
            mem[x] += mem[y];
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
            mem[y] += mem[x];
        }
        sz--;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int n,m,p[100010],x,y;
signed main(){
    I(n); I(m);
    REP(i,n) I(p[i]);
    UnionFind uf = UnionFind(n);
    REP(i,m){
        I(x); I(y);
        x--; y--;
        uf.unite(x,y);
    }
    int ret = 0;
    REP(i,n){
        ret += uf.same(i,p[i]) ? 1 : 0;
    }
    cout << ret << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Equals
User omi
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2763 Byte
Status RE
Exec Time 115 ms
Memory 3456 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:100:9: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     I(n); I(m);
         ^
./Main.cpp:100:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     I(n); I(m);
               ^
./Main.cpp:101:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     REP(i,n) I(p[i]);
                     ^
./Main.cpp:104:13: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         I(x); I(y);
             ^
./Main.cpp:104:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         I(x); I(y);
                   ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 1
RE × 3
AC × 10
WA × 9
RE × 4
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt
Case Name Status Exec Time Memory
0_000.txt RE 98 ms 256 KB
0_001.txt RE 98 ms 256 KB
0_002.txt AC 1 ms 256 KB
0_003.txt RE 99 ms 256 KB
1_004.txt RE 115 ms 256 KB
1_005.txt WA 31 ms 3328 KB
1_006.txt AC 37 ms 3328 KB
1_007.txt AC 1 ms 256 KB
1_008.txt AC 1 ms 256 KB
1_009.txt AC 1 ms 256 KB
1_010.txt AC 1 ms 256 KB
1_011.txt WA 1 ms 256 KB
1_012.txt WA 1 ms 256 KB
1_013.txt AC 2 ms 256 KB
1_014.txt AC 2 ms 256 KB
1_015.txt WA 1 ms 256 KB
1_016.txt WA 1 ms 256 KB
1_017.txt WA 2 ms 256 KB
1_018.txt AC 16 ms 256 KB
1_019.txt AC 12 ms 3328 KB
1_020.txt WA 12 ms 3328 KB
1_021.txt WA 12 ms 3328 KB
1_022.txt WA 37 ms 3456 KB