제출 #1102527

#제출 시각아이디문제언어결과실행 시간메모리
1102527EkinOnalKutije (COCI21_kutije)C++17
70 / 70
99 ms1880 KiB
// #pragma GCC optimize("O3,unroll-loops,Ofast")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
using namespace std;

const short N = 1000+2;

struct DSU {
	short e[N]; 
	DSU(){for(short i = 1; i < N-1; i++) e[i]=-1;}

	short get(short x) { return e[x] < 0 ? x : e[x] = get(e[x]); } 
	bool sameSet(short a, short b) { return get(a) == get(b); }
	short size(short x) { return -e[get(x)]; }
	bool unite(short x, short y) { // union by size
		x = get(x), y = get(y); if (x == y) return 0;
		if (e[x] > e[y]) swap(x,y);
		e[x] += e[y]; e[y] = x;  return 1;
	}
};

DSU t;
short n,m,a,b;
int q;
int32_t main(){
	ios_base::sync_with_stdio(0); cin.tie(0);		
	cin>>n>>m>>q;

	for(short i=1;i<=m;i++){
		for(short j=1;j<=n;j++){
			cin>>a; 
			t.unite(j,a);
		}
	}
	while(q--){
		cin>>a>>b;
		if(t.sameSet(a,b)) cout<<"DA\n";
		else cout<<"NE\n";
	} 			
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...