This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define ll long long
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 998244353
using namespace std;
int dad[1005];
int find(int x){
if(dad[x]==x) return x;
return dad[x]=find(dad[x]);
}
void unite(int x, int y){
dad[find(x)] = find(y);
}
void solve(){
int n,m,q;
cin >> n >> m >> q;
for(int i=1; i<=n; i++) dad[i]=i;
for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
int a; cin >> a;
unite(a, j);
}
}
while(q--){
int a,b; cin >> a >> b;
if(find(a)==find(b)) cout << "DA" << endl;
else cout << "NE" << endl;
}
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
ll 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... |