Submission #423267
Source Code Expand
#include<iostream> using namespace std; int par[100000]; int ran[100000]; void init(int n){ for(int i=0;i<n;i++){ par[i]=i; ran[i]=0; } } int root(int x){ return par[x] == x?x:par[x]=root(par[x]); } bool same(int x,int y){ return root(x)==root(y); } void unite(int x,int y){ x=root(x); y=root(y); if(x==y) return; if(ran[x]<ran[y]){ par[x]=y; } else{ par[y]=x; if(ran[x]==ran[y]) ran[x]++; } } int main(){ int N,Q; cin>>N>>Q; init(N); while(Q!=0){ int P,A,B; cin>>P>>A>>B; if(P==0) unite(A,B); else{ if(same(A,B)) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } }
Submission Info
Submission Time | |
---|---|
Task | B - Union Find |
User | yata |
Language | C++ (GCC 4.9.2) |
Score | 0 |
Code Size | 695 Byte |
Status | TLE |
Exec Time | 5061 ms |
Memory | 1696 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||
Status |
|
|
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 | TLE | 5037 ms | 928 KB |
subtask_01_01.txt | TLE | 5037 ms | 876 KB |
subtask_01_02.txt | TLE | 5037 ms | 1588 KB |
subtask_01_03.txt | TLE | 5061 ms | 816 KB |
subtask_01_04.txt | TLE | 5037 ms | 1584 KB |
subtask_01_05.txt | TLE | 5034 ms | 924 KB |
subtask_01_06.txt | TLE | 5035 ms | 1588 KB |
subtask_01_07.txt | TLE | 5034 ms | 804 KB |
subtask_01_08.txt | TLE | 5037 ms | 1692 KB |
subtask_01_09.txt | TLE | 5036 ms | 928 KB |
subtask_01_10.txt | TLE | 5037 ms | 1592 KB |
subtask_01_11.txt | TLE | 5037 ms | 864 KB |
subtask_01_12.txt | TLE | 5037 ms | 1696 KB |
subtask_01_13.txt | TLE | 5037 ms | 840 KB |
subtask_01_14.txt | TLE | 5037 ms | 1684 KB |
subtask_01_15.txt | TLE | 5037 ms | 924 KB |
subtask_01_16.txt | TLE | 5033 ms | 1584 KB |
subtask_01_17.txt | TLE | 5037 ms | 1580 KB |
subtask_01_18.txt | TLE | 5037 ms | 1696 KB |