Submission #515818

#TimeUsernameProblemLanguageResultExecution timeMemory
515818aris12345678Kutije (COCI21_kutije)C++14
70 / 70
210 ms9392 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...