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;
#pragma GCC optimize("Ofast,O3,unroll-loops")
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpi vector<pii>
#define vvpi vector<vpi>
#define vb vector<bool>
#define vvb vector<vb>
#define endl "\n"
#define sp << " " <<
#define F(i, s, n) for(int i = s; i < n; i++)
#define pb push_back
#define fi first
#define se second
int inf = LLONG_MAX >> 3;
vi dad(1001);
int find(int a) {
if(dad[a] == a) return a;
return dad[a] = find(dad[a]);
}
void unite(int a, int b) {
dad[find(a)] = find(b);
}
void solve() {
int n, m, q;
cin >> n >> m >> q;
F(i, 0, n) dad[i] = i;
F(i, 0, m) {
F(j, 0, n) {
int x;
cin >> x;
x--;
unite(x, j);
}
}
F(i, 0, q) {
int x, y;
cin >> x >> y;
x--, y--;
if(find(x) == find(y)) cout << "DA" << endl;
else cout << "NE" << endl;
}
}
void setIO() {
ios::sync_with_stdio(0); cin.tie(0);
#ifdef Local
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
signed main() {
setIO();
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... |