This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define lim 1000000
#define till 1000001
// # of primes till 1e6 = 7e4
using namespace std;
using pii = array<int,2>;
const int mod=1000000007ll;
bool v[1000][1000];
bool vis[1000];
int n,m,q;
void dfs(int i){
bool might=0;
for(int j=0;j<n;j++){
if(v[i][j]&&!vis[j]){
vis[j]=1;
for(int k=0;k<n;k++){
if(v[j][k]&&!v[i][k]){
v[i][k]=1;
might=1;
}
}
}
}
if(might)dfs(i);
}
void solve(){
cin>>n>>m>>q;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
v[i][j]=0;
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
int tem;
cin>>tem;
tem--;
v[tem][j]=1;
}
}
for(int i=0;i<n;i++){
memset(vis,0,n);
dfs(i);
}
for(int i=0;i<n;i++){
v[i][i]=1;
}
while(q--){
int x,y;
cin>>x>>y;
x--,y--;
if(v[x][y]==1){
cout<<"DA\n";
}else{
cout<<"NE\n";
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t=1;
//cin>>t;
while (t--)
{
solve();
}
}
# | 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... |