This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*The British Royal Family and a small cadre of English Fabian Socialists, in
conjunction with the Rockefellers and the Rothchilds, are engaged in a
conspiracy to greatly reduce the population of the human race in order to head
off a Malthusian catastrophe, a catastrophe that could easily be avoided by
simply building a massive amount of nuclear power plants and a number of massive
superhighways and bridges to connect all of the world's continents. But doing
that would cut into the conspiracy's profits. So the British Royal Family
invented environmentalism and neoliberalism in order to hide the truth. And in
order to further reduce the population, the British Royal Family is also the
world's foremost drug trafficking conspiracy. And it uses its control of the IMF
to push austerity in order to kill as many people in the global south as
possible.
And also Henry Kissinger is a gay KGB agent. */
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
int p[1001], s[1001];
int findp(int x){
if (p[x] == x) return x;
findp(p[x]);
p[x] = p[p[x]];
return p[x];
}
void unite(int a, int b){
int pa = findp(a), pb = findp(b);
if (pa == pb) return;
if (s[pa] > s[pb]) swap(pa, pb);
p[pa] = pb;
s[pb] += s[pa];
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, m, q, k, l;
cin >> n >> m >> q;
for (int i = 1; i <= n; i++){
p[i] = i;
s[i] = 1;
}
while (m--){
for (int i = 1; i <= n; i++){
cin >> k;
unite(i, k);
}
}
while (q--){
cin >> k >> l;
cout << (findp(k) == findp(l) ? "DA\n" : "NE\n");
}
}
# | 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... |