Submission #497229

#TimeUsernameProblemLanguageResultExecution timeMemory
497229Abrar_Al_SamitKutije (COCI21_kutije)C++17
70 / 70
166 ms18232 KiB
#include<bits/stdc++.h>
using namespace std;
const int MX = 1005;
vector<int>g[MX];
bool vis[MX];
int comp[MX];
void DFS(int v, int no) {
	vis[v] = 1;
	comp[v] = no;
	for(auto u : g[v]) if(!vis[u]) {
		DFS(u, no);
	}
}
void PlayGround() {
	int n, m, q; cin >> n >> m >> q;
	while(m--) {
		for(int i=1; i<=n; ++i) {
			int to; cin >> to;
			g[i].push_back(to);
			g[to].push_back(i);
		}
	}
	int cur = 1;
	for(int i=1; i<=n; ++i) if(!vis[i]) {
		DFS(i, cur);
		++cur;
	}
	while(q--) {
		int a, b; cin >> a >> b;
		if(comp[a]==comp[b]) {
			cout << "DA\n";
		} else {
			cout << "NE\n";
		}
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	PlayGround();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...