제출 #1202332

#제출 시각아이디문제언어결과실행 시간메모리
1202332MighilonKutije (COCI21_kutije)C++20
70 / 70
97 ms1976 KiB
#include <bits/stdc++.h>
using namespace std;
 
#ifdef DEBUG
#include "../Library/debug.h"
#else
#define dbg(x...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl; 
 
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i)
#define trav(a, x) for (auto& a : x)
#define f first 
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
 
const char nl = '\n';
const int INF = 1e9;
const int MOD = 1e9 + 7;

struct DSU {
    vector<int> par, sz;
    int c;
    DSU(int n) : par(n), c(n) {
        sz.resize(n, 1); 
        for (int i = 0; i < n; ++i) par[i] = i;
    }
    int find(int i) {
        return par[i] == i ? i : (par[i] = find(par[i]));
    }
    bool same(int i, int j) {
        return find(i) == find(j);
    }
    int get_size(int i) {
        return sz[find(i)];
    }
    int count() {
        return c;
    }
    int merge(int i, int j) {
        if ((i = find(i)) == (j = find(j))) return -1;
        else --c;
        if (sz[i] > sz[j]) swap(i, j);
        par[i] = j;
        sz[j] += sz[i];
        return j;
    }
};

void solve(){
    int n, m,q;
    cin>>n>>m>>q;
    DSU dsu(n+1);
    F0R(i,m){
        F0R(j,n){
            int a;
            cin>>a;
            dsu.merge(a,j+1);
        }
    }
    F0R(i,q){
        int a,b;
        cin>>a>>b;
        if(dsu.same(a,b))
            cout<<"DA"<<nl;
        else cout<<"NE"<<nl;
    }
}
 
int32_t main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int TC = 1;
    // cin >> TC;
    while(TC--){
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...