답안 #528352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528352 2022-02-20T06:54:10 Z N1NT3NDO Kutije (COCI21_kutije) C++14
70 / 70
211 ms 2512 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) (int)x.size()
#define fi first
#define sd second
#define all(x) x.begin(), x.end()
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 1010;
//bitset<N> bt[N];
int n, q, m, p[N], sz[N];
set<int> se[N];

int f(int x)
{
    return p[x] = (p[x] == x ? x : f(p[x]));
}

void link(int a, int b)
{
    a = f(a); b = f(b);
    if (a == b) return;
    if (sz[a] < sz[b]) swap(a, b);
    p[b] = a;
    sz[a] += sz[b];
    for(auto u : se[b]) se[a].insert(u);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> q;
    for(int i = 1; i <= n; i++)
    {
        p[i] = i;
        se[i].insert(i);
        sz[i] = 1;
    }

    for(int i = 1; i <= m; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            int x;
            cin >> x;
            link(j, x);
        }
    }

    while(q--)
    {
        int a, b;
        cin >> a >> b;
        if (se[f(b)].find(a) != se[f(b)].end()) cout << "DA" << '\n';
        else cout << "NE" << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 2040 KB Output is correct
2 Correct 115 ms 1764 KB Output is correct
3 Correct 92 ms 1640 KB Output is correct
4 Correct 141 ms 2200 KB Output is correct
5 Correct 111 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 2040 KB Output is correct
2 Correct 115 ms 1764 KB Output is correct
3 Correct 92 ms 1640 KB Output is correct
4 Correct 141 ms 2200 KB Output is correct
5 Correct 111 ms 1876 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 376 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 177 ms 2416 KB Output is correct
27 Correct 188 ms 2460 KB Output is correct
28 Correct 146 ms 2208 KB Output is correct
29 Correct 211 ms 2488 KB Output is correct
30 Correct 136 ms 2132 KB Output is correct
31 Correct 144 ms 2116 KB Output is correct
32 Correct 190 ms 2364 KB Output is correct
33 Correct 159 ms 2340 KB Output is correct
34 Correct 189 ms 2512 KB Output is correct
35 Correct 191 ms 2340 KB Output is correct