Submission #420560


Source Code Expand

#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>    //queue, priority_queue
#include <set>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <bitset>
#include <limits.h>
#include <float.h>

using namespace std;

#define REPN(n) for(int i=0; i<n; i++)
#define REPNN(n) for(int i=1; i<=n; i++)
#define REP(k, n) for(int i=k; i<n; i++)

#define MS 100001

int parent[MS];
int n, q, p, a, b;

int root(int x){
    if (parent[x] == x) {
        return x;
    }else{
        return parent[x] = root(parent[x]);
    }
}

bool same(int a, int b){
    return root(a) == root(b);
}

void unite(int a, int b){
    a = root(a);
    b = root(b);
    if (a==b) {
        return;
    }
    parent[a] = b;
}

void init(){
    cin >> n >> q;
    for (int i=0; i<n; i++) {
        parent[i] = i;
    }
    for (int i=0; i<q; i++) {
        cin >> p >> a >> b;
        if (!p) {
            unite(a, b);
        }else{
            if (same(a, b)) {
                cout << "Yes\n";
            }else{
                cout << "No\n";
            }
        }
    }
    
}

int main(int argc, const char * argv[]) {
    init();
    
    return 0;
}

Submission Info

Submission Time
Task B - Union Find
User ParaDevil
Language C++ (GCC 4.9.2)
Score 100
Code Size 1328 Byte
Status AC
Exec Time 925 ms
Memory 1316 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 19
Set Name Test Cases
Sample 00_sample_01.txt
All 00_sample_01.txt, subtask_01_01.txt, subtask_01_02.txt, subtask_01_03.txt, subtask_01_04.txt, subtask_01_05.txt, subtask_01_06.txt, subtask_01_07.txt, subtask_01_08.txt, subtask_01_09.txt, subtask_01_10.txt, subtask_01_11.txt, subtask_01_12.txt, subtask_01_13.txt, subtask_01_14.txt, subtask_01_15.txt, subtask_01_16.txt, subtask_01_17.txt, subtask_01_18.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 23 ms 924 KB
subtask_01_01.txt AC 494 ms 928 KB
subtask_01_02.txt AC 23 ms 1184 KB
subtask_01_03.txt AC 750 ms 716 KB
subtask_01_04.txt AC 925 ms 1316 KB
subtask_01_05.txt AC 62 ms 748 KB
subtask_01_06.txt AC 71 ms 1308 KB
subtask_01_07.txt AC 741 ms 796 KB
subtask_01_08.txt AC 827 ms 1312 KB
subtask_01_09.txt AC 22 ms 796 KB
subtask_01_10.txt AC 27 ms 1184 KB
subtask_01_11.txt AC 700 ms 800 KB
subtask_01_12.txt AC 815 ms 1308 KB
subtask_01_13.txt AC 629 ms 924 KB
subtask_01_14.txt AC 25 ms 1120 KB
subtask_01_15.txt AC 720 ms 780 KB
subtask_01_16.txt AC 832 ms 1180 KB
subtask_01_17.txt AC 646 ms 1184 KB
subtask_01_18.txt AC 631 ms 1124 KB