답안 #851818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851818 2023-09-20T16:22:24 Z vjudge1 Kutije (COCI21_kutije) C++17
70 / 70
136 ms 1984 KB
//author:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

#define ONLINE_JUDGE

struct DSU {
    vector <int> par;
    DSU(int n) {
        par.resize(n);
        iota(par.begin(), par.end(), 0ll);
    }

    bool same(int a, int b) {
        return get(a) == get(b);
    }

    inline int get(int a) {
        return par[a] = (par[a] == a ? a : get(par[a]));
    }

    void unite(int u, int v) {
        par[get(u)] = get(v);
    }
};

void solve() {
    int n, m, q; 
    cin >> n >> m >> q;

    DSU dsu(n +1);
    for(int i = 1; i <= m; i++) {
        for(int j = 1; j <= n; j++) {
            int x; 
            cin >> x;
            dsu.unite(j, x);
        }
    }

    for(int i = 1; i <= q; i++) {
        int a, b;
        cin >> a >> b;

        cout << (dsu.same(a, b) ? "DA" : "NE") << "\n";
    }
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    while(t--)
        solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 1912 KB Output is correct
2 Correct 61 ms 1620 KB Output is correct
3 Correct 62 ms 1556 KB Output is correct
4 Correct 82 ms 1864 KB Output is correct
5 Correct 75 ms 1944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 548 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 548 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 1912 KB Output is correct
2 Correct 61 ms 1620 KB Output is correct
3 Correct 62 ms 1556 KB Output is correct
4 Correct 82 ms 1864 KB Output is correct
5 Correct 75 ms 1944 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 548 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 2 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 136 ms 1796 KB Output is correct
27 Correct 121 ms 1872 KB Output is correct
28 Correct 104 ms 1984 KB Output is correct
29 Correct 133 ms 1768 KB Output is correct
30 Correct 113 ms 1520 KB Output is correct
31 Correct 103 ms 1464 KB Output is correct
32 Correct 133 ms 1984 KB Output is correct
33 Correct 125 ms 1812 KB Output is correct
34 Correct 122 ms 1816 KB Output is correct
35 Correct 125 ms 1872 KB Output is correct