// In the name of God, the Most Gracious, the Most Merciful.
// iflbot(); - @yavuzskarahan
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define file(x) freopen(x ".in", "r", stdin); freopen(x ".out", "w", stdout);
#define F0R(i, R) for (int i = (0); i < (R); i++)
#define FOR(i, L, R) for (int i = (L); i <= (R); i++)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define int long long
#define pb push_back
#define ub(v, a) upper_bound((v).begin(), (v).end(), (a))
#define lb(v, a) lower_bound((v).begin(), (v).end(), (a))
#define f first
#define s second
#define space << " " <<
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define now chrono::high_resolution_clock::now()
const long long N = 2e5+5;
const long long MOD = 1e9+7;
int n, m, q, a, b, u, v;
vi adj[1005];
bool visited[1005];
int parent[1005];
inline int find(int a){
if (a==parent[a]) return a;
else return parent[a] = find(parent[a]);
}
inline void unite(int a, int b){
a = find(a);
b = find(b);
parent[b] = a;
return;
}
inline bool dfs(int v, int p, int target){
if (v==target) return true;
if (visited[v]) return false;
visited[v] = true;
for(auto u : adj[v]){
if (dfs(u,v,target)) return true;
}
return false;
}
inline int solve(){
cin >> n >> m >> q;
FOR(i,1,n) parent[i] = i;
FOR(i,1,m){
FOR(j,1,n){
cin >> a;
unite(j,a);
}
}
while(q--){
FOR(i,0,n+1) visited[i] = false;
cin >> a >> b;
if (find(a) == find(b)) cout << "DA" << endl;
else cout << "NE" << endl;
}
return 0;
}
int32_t main() {
#ifdef LOCAL
auto start = now;
#endif
fast;
//file("wormsort");
int t = 1;
//cin >> t;
while(t--){
solve();
}
#ifdef LOCAL
auto end = now;
chrono::duration<double> elapsed = end - start;
cout << endl << "runtime: " << endl << elapsed.count() << endl;
#endif
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
741 ms |
4012 KB |
Output is correct |
2 |
Correct |
649 ms |
4940 KB |
Output is correct |
3 |
Correct |
607 ms |
4752 KB |
Output is correct |
4 |
Correct |
745 ms |
5708 KB |
Output is correct |
5 |
Correct |
742 ms |
5720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
741 ms |
4012 KB |
Output is correct |
2 |
Correct |
649 ms |
4940 KB |
Output is correct |
3 |
Correct |
607 ms |
4752 KB |
Output is correct |
4 |
Correct |
745 ms |
5708 KB |
Output is correct |
5 |
Correct |
742 ms |
5720 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
783 ms |
9384 KB |
Output is correct |
27 |
Correct |
779 ms |
9436 KB |
Output is correct |
28 |
Correct |
645 ms |
8012 KB |
Output is correct |
29 |
Correct |
754 ms |
9048 KB |
Output is correct |
30 |
Correct |
642 ms |
8056 KB |
Output is correct |
31 |
Correct |
635 ms |
7984 KB |
Output is correct |
32 |
Correct |
767 ms |
9516 KB |
Output is correct |
33 |
Correct |
805 ms |
9436 KB |
Output is correct |
34 |
Correct |
770 ms |
9508 KB |
Output is correct |
35 |
Correct |
787 ms |
9548 KB |
Output is correct |