이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |