Submission #1258494

#TimeUsernameProblemLanguageResultExecution timeMemory
1258494sokratisiKutije (COCI21_kutije)C++20
10 / 70
53 ms1856 KiB
#include <bits/stdc++.h>

using namespace std;

int n, m, q;
int rep[1005], sz[1005];
int p[1005];

int find_rep(int a) {
    if (a == rep[a]) return a;
    return rep[a] = find_rep(rep[a]);
}

void connect(int a, int b) {
    a = find_rep(a);
    b = find_rep(b);
    if (a == b) return;
    if (sz[a] < sz[b]) swap(a, b);
    rep[b] = a;
    sz[a] += sz[b];
}

int main() {
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 1; i <= n; i++) rep[i] = i;
    for (int i = 1; i <= n; i++) sz[i] = 1;

    while (m--) {
        for (int i = 1; i <= m; i++) scanf("%d", &p[i]);
        for (int i = 1; i <= m; i++) connect(i, p[i]);
    }

    while (q--) {
        int a, b;
        scanf("%d%d", &a, &b);
        if (find_rep(a) == find_rep(b)) printf("DA\n");
        else printf("NE\n");
    }

    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d%d%d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:29:43: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         for (int i = 1; i <= m; i++) scanf("%d", &p[i]);
      |                                      ~~~~~^~~~~~~~~~~~~
Main.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...