/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e15+7;
const ll ous = 2e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
std::vector<std::pair<ll , std::string>> ar;
std::vector<ll> par , siz;
ll n , m , q;
ll fin(ll x){
if(par[x] == x){
return x;
}
return par[x] = fin(par[x]);
}
void merge(ll x , ll y){
x = fin(x);y = fin(y);
if(x !=y){
if(siz[y] > siz[x]){
std::swap(x , y);
}
siz[x]+=siz[y];
par[y] = x;
}
}
void solve(){
std::cin >> n >> m >> q;
par.resize(n+5);
siz.resize(n+5 , 1);
for(ll i = 0 ;n>=i;i++){
par[i] = i;
}
for(ll i = 0;m>i;i++){
for(ll j = 0;n>j;j++){
ll x;std::cin >> x;
merge(j+1 , x);
}
}
while(q--){
ll x , y;std::cin >> x >> y;
if(fin(x) == fin(y)){
std::cout << "DA\n";
}
else{
std::cout << "NE\n";
}
}
return;/**/
}
signed main(){
std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
ll t=1;
//std::cin >> t;
ll o = 1;
while(t--){
//cout << "Case " << o++ << ":\n";
solve();
}
return 0;
}
Compilation message
Main.cpp:5:78: warning: "/*" within comment [-Wcomment]
5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
|
Main.cpp: In function 'int main()':
Main.cpp:70:8: warning: unused variable 'o' [-Wunused-variable]
70 | ll o = 1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
5580 KB |
Output is correct |
2 |
Correct |
68 ms |
4936 KB |
Output is correct |
3 |
Correct |
63 ms |
4608 KB |
Output is correct |
4 |
Correct |
75 ms |
5624 KB |
Output is correct |
5 |
Correct |
90 ms |
5616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
272 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
5580 KB |
Output is correct |
2 |
Correct |
68 ms |
4936 KB |
Output is correct |
3 |
Correct |
63 ms |
4608 KB |
Output is correct |
4 |
Correct |
75 ms |
5624 KB |
Output is correct |
5 |
Correct |
90 ms |
5616 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
356 KB |
Output is correct |
14 |
Correct |
1 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
272 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
135 ms |
9416 KB |
Output is correct |
27 |
Correct |
151 ms |
9368 KB |
Output is correct |
28 |
Correct |
113 ms |
7972 KB |
Output is correct |
29 |
Correct |
134 ms |
9128 KB |
Output is correct |
30 |
Correct |
127 ms |
7988 KB |
Output is correct |
31 |
Correct |
129 ms |
8024 KB |
Output is correct |
32 |
Correct |
131 ms |
9392 KB |
Output is correct |
33 |
Correct |
149 ms |
9348 KB |
Output is correct |
34 |
Correct |
140 ms |
9400 KB |
Output is correct |
35 |
Correct |
139 ms |
9424 KB |
Output is correct |