#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;
bitset<1000> v[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;
if(((v[i])^(v[j]))!=0){
might=1;
}
v[i]|=v[j];
}
}
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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
2016 KB |
Output is correct |
2 |
Correct |
74 ms |
1660 KB |
Output is correct |
3 |
Correct |
61 ms |
1604 KB |
Output is correct |
4 |
Correct |
85 ms |
1948 KB |
Output is correct |
5 |
Correct |
67 ms |
1872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
2016 KB |
Output is correct |
2 |
Correct |
74 ms |
1660 KB |
Output is correct |
3 |
Correct |
61 ms |
1604 KB |
Output is correct |
4 |
Correct |
85 ms |
1948 KB |
Output is correct |
5 |
Correct |
67 ms |
1872 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
113 ms |
1872 KB |
Output is correct |
27 |
Correct |
118 ms |
1872 KB |
Output is correct |
28 |
Correct |
105 ms |
1656 KB |
Output is correct |
29 |
Correct |
126 ms |
1872 KB |
Output is correct |
30 |
Correct |
102 ms |
1580 KB |
Output is correct |
31 |
Correct |
95 ms |
1616 KB |
Output is correct |
32 |
Correct |
131 ms |
2132 KB |
Output is correct |
33 |
Correct |
115 ms |
1872 KB |
Output is correct |
34 |
Correct |
115 ms |
1876 KB |
Output is correct |
35 |
Correct |
127 ms |
1836 KB |
Output is correct |