This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <string>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
const int mx = 1'000;
vvi edge(1+mx);
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
for(int j = 1; j <= m; j++)
{
for(int i = 1; i <= n; i++)
{
int p;
cin >> p;
edge[p].push_back(i);
edge[i].push_back(p);
}
}
vi cc(1+n, 0);
int cc_count = 0;
for(int i = 1; i <= n; i++)
{
if(cc[i]) continue;
cc_count++;
cc[i] = cc_count;
queue<int> tbv;
tbv.push(i);
while(!tbv.empty())
{
int u = tbv.front();
tbv.pop();
for(int v: edge[u])
{
if(cc[v]) continue;
cc[v] = cc_count;
tbv.push(v);
}
}
}
for(int x = 1; x <= q; x++)
{
int a, b;
cin >> a >> b;
if(cc[a] == cc[b]) cout << "DA\n";
else cout << "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... |