This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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('<');
if (pseq != -1) {
int a = stoll(S.substr(0, pseq));
int b = stoll(S.substr(pseq + 1, N - pseq));
dsu.Unite(a, b);
} else {
int a = stoll(S.substr(0, pslg));
int b = stoll(S.substr(pslg + 1, N - pslg));
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() {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |