Submission #1120576

#TimeUsernameProblemLanguageResultExecution timeMemory
1120576coolboy19521KOVANICE (COI15_kovanice)C++17
0 / 100
5 ms3064 KiB
#include"bits/stdc++.h"
using namespace std;

const int mxN = 300005;

struct Dsu {
    int ar[mxN];
    Dsu() {
        fill(ar, ar + mxN, -1);
    }
    int Find(int u) {
        if (0 > ar[u]) {
            return u;
        } else {
            return ar[u] = Find(ar[u]);
        }
    }
    void Unite(int u, int v) {
        u = Find(u);
        v = Find(v);
        if (ar[u] > ar[v]) {
            swap(u, v);
        }
        ar[u] += ar[v];
        ar[v] = u;
    }
} dsu;

main() {
    int N, M, V;
    cin >> N >> M >> V;

    int l = -1;
    int g = -1;

    for (int i = 0; i < V; i ++) {
        string S;
        cin >> S;
        int N = S.size();
        int pseq = S.find('=');
        int pslg = S.find('<');
        assert(pseq < S.size());
        if (pseq != -1) {
            int a = stoll(S.substr(0, pseq));
            int b = stoll(S.substr(pseq + 1, N - pseq - 1));
            dsu.Unite(a, b);
        } else {
            int a = stoll(S.substr(0, pslg));
            int b = stoll(S.substr(pslg + 1, N - pslg - 1));
            l = a, g = b;
        }
    }

    if (-1 == l && -1 == g) {
        for (int i = 0; i < M; i ++) {
            cout << '?' << endl;
        }
    } else {
        for (int i = 1; i <= M; i ++) {
            if (dsu.Find(i) == dsu.Find(l)) {
                cout << "K1" << endl;
            } else if (dsu.Find(i) == dsu.Find(g)) {
                cout << "K2" << endl;
            } else {
                cout << '?' << endl;
            }
        }
    }
}

Compilation message (stderr)

kovanice.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main() {
      | ^~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from kovanice.cpp:1:
kovanice.cpp: In function 'int main()':
kovanice.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         assert(pseq < S.size());
      |                ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...