Submission #537886

# Submission time Handle Problem Language Result Execution time Memory
537886 2022-03-15T19:04:25 Z davi_bart Kutije (COCI21_kutije) C++14
70 / 70
151 ms 9404 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define ld long double
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N, M, Q;
vector<int> v[1010];
struct dsu {
    int par[1010];
    void init() {
        iota(par, par + 1005, 0);
    }
    int p(int pos) {
        return par[pos] = (pos == par[pos] ? pos : p(par[pos]));
    }
    void unite(int a, int b) {
        a = p(a);
        b = p(b);
        if (a == b) return;
        par[a] = b;
    }
};
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> M >> Q;
    dsu d;
    d.init();
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            int x;
            cin >> x;
            x--;
            d.unite(x, j);
        }
    }
    for (int i = 0; i < Q; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if (d.p(a) == d.p(b))
            cout << "DA\n";
        else
            cout << "NE\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 75 ms 5596 KB Output is correct
2 Correct 64 ms 4832 KB Output is correct
3 Correct 66 ms 4644 KB Output is correct
4 Correct 76 ms 5616 KB Output is correct
5 Correct 85 ms 5540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 376 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 376 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 388 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 5596 KB Output is correct
2 Correct 64 ms 4832 KB Output is correct
3 Correct 66 ms 4644 KB Output is correct
4 Correct 76 ms 5616 KB Output is correct
5 Correct 85 ms 5540 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 376 KB Output is correct
12 Correct 1 ms 376 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 376 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 388 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
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 2 ms 380 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 142 ms 9400 KB Output is correct
27 Correct 149 ms 9404 KB Output is correct
28 Correct 144 ms 7852 KB Output is correct
29 Correct 133 ms 9160 KB Output is correct
30 Correct 131 ms 8008 KB Output is correct
31 Correct 115 ms 8076 KB Output is correct
32 Correct 132 ms 9404 KB Output is correct
33 Correct 151 ms 9404 KB Output is correct
34 Correct 139 ms 9404 KB Output is correct
35 Correct 148 ms 9404 KB Output is correct