Submission #7973847


Source Code Expand

#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
class UnionFind{
  public: V par;

  UnionFind(int N) : par(N){
    par.resize(N);
    REP(i , N)  par[i] = i;
  }

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

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
  }

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

};

int main(void){

    int N, Q; cin >> N >> Q;
    UnionFind uf(N);

    for(int i = 0 ; i < Q ; i++){
      int Q, A, B;	cin >> Q >> A >> B;
      if(!Q){
        uf.unite(A - 1, B - 1);
      }else{
		if(uf.same(A - 1, B - 1)){
          	cout << "Yes" << endl;
        }else{
          	cout << "No" << endl;
        }
      }
    }

    return 0;
}

Submission Info

Submission Time
Task B - Union Find
User catalneko0125
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1534 Byte
Status RE
Exec Time 462 ms
Memory 1280 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
RE × 1
AC × 14
WA × 4
RE × 1
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 RE 98 ms 256 KB
subtask_01_01.txt AC 268 ms 640 KB
subtask_01_02.txt AC 1 ms 640 KB
subtask_01_03.txt AC 416 ms 1024 KB
subtask_01_04.txt AC 454 ms 1280 KB
subtask_01_05.txt AC 25 ms 256 KB
subtask_01_06.txt AC 26 ms 640 KB
subtask_01_07.txt WA 422 ms 768 KB
subtask_01_08.txt AC 462 ms 1280 KB
subtask_01_09.txt WA 1 ms 256 KB
subtask_01_10.txt AC 1 ms 640 KB
subtask_01_11.txt WA 403 ms 896 KB
subtask_01_12.txt AC 461 ms 1280 KB
subtask_01_13.txt AC 352 ms 768 KB
subtask_01_14.txt AC 2 ms 640 KB
subtask_01_15.txt WA 417 ms 896 KB
subtask_01_16.txt AC 453 ms 1280 KB
subtask_01_17.txt AC 313 ms 1024 KB
subtask_01_18.txt AC 304 ms 896 KB