Submission #515818

# Submission time Handle Problem Language Result Execution time Memory
515818 2022-01-19T19:03:19 Z aris12345678 Kutije (COCI21_kutije) C++14
70 / 70
210 ms 9392 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 1005;
int par[mxN], sz[mxN];

void make_set(int x) {
    par[x] = x, sz[x] = 1;
}

int find_set(int x) {
    return par[x] == x ? x : par[x] = find_set(par[x]);
}

void union_sets(int x, int y) {
    x = find_set(x), y = find_set(y);
    if(x == y) return;
    if(sz[x] < sz[y])
        swap(x, y);
    par[y] = x, sz[x] += sz[y];
}

int main() {
    int n, m, q;
    scanf("%d %d %d", &n, &m, &q);
    for(int i = 0; i < n; i++)
        make_set(i);
    for(int i = 0; i < m; i++) {
        for(int j = 0; j < n; j++) {
            int x;
            scanf("%d", &x);
            union_sets(j, x-1);
        }
    }
    while(q--) {
        int x, y;
        scanf("%d %d", &x, &y);
        if(find_set(x-1) == find_set(y-1))
            printf("DA\n");
        else
            printf("NE\n");
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d %d %d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |             scanf("%d", &x);
      |             ~~~~~^~~~~~~~~~
Main.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 104 ms 5584 KB Output is correct
2 Correct 91 ms 4848 KB Output is correct
3 Correct 87 ms 4532 KB Output is correct
4 Correct 103 ms 5552 KB Output is correct
5 Correct 111 ms 5480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 5584 KB Output is correct
2 Correct 91 ms 4848 KB Output is correct
3 Correct 87 ms 4532 KB Output is correct
4 Correct 103 ms 5552 KB Output is correct
5 Correct 111 ms 5480 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 296 KB Output is correct
26 Correct 186 ms 9344 KB Output is correct
27 Correct 179 ms 9392 KB Output is correct
28 Correct 167 ms 7692 KB Output is correct
29 Correct 172 ms 9096 KB Output is correct
30 Correct 157 ms 7944 KB Output is correct
31 Correct 165 ms 8004 KB Output is correct
32 Correct 205 ms 9360 KB Output is correct
33 Correct 191 ms 9352 KB Output is correct
34 Correct 210 ms 9364 KB Output is correct
35 Correct 180 ms 9344 KB Output is correct