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 <bits/stdc++.h>
using namespace std ;
const int MAX = 1000 + 10 ;
int arr[MAX] ;
int n , m , q ;
vector< vector<int> >adj(MAX) ;
int val[MAX] ;
void dfs(int node)
{
for(auto &child : adj[node])
{
if(!val[child])
val[child] = val[node] , dfs(child) ;
}
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>m>>q ;
for(int i = 1 ; i <= m ; ++i)
{
for(int i = 1 ; i <= n ; ++i)
{
int x ;
cin>>x ;
adj[x].push_back(i) ;
}
}
for(int i = 1 ; i <= n ; ++i)
{
if(val[i])
continue ;
val[i] = i , dfs(i) ;
}
while(q--)
{
int x , y ;
cin>>x>>y ;
if(val[x] == val[y])
cout<<"DA\n" ;
else
cout<<"NE\n" ;
}
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... |