This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author - alimammadzade
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1;
vector<int> g[N];
bool vis[N];
int res[N], n, m, v, k1, k2, a, b;
void dfs(int u, int k) {
res[u] = k;
vis[u] = 1;
for (int v : g[u])
if (!vis[v])
dfs(v, k);
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
// system("cls"), freopen("in.txt", "r", stdin);
cin >> n >> m >> v;
while (v--) {
char c;
cin >> a >> c >> b;
if (c == '=') {
g[a].push_back(b);
g[b].push_back(a);
}
else {
k1 = a;
k2 = b;
}
}
if (k1) dfs(k1, 1);
if (k2) dfs(k2, 2);
for (int i = 1; i <= m; i++)
if (res[i]) cout << 'K' << res[i] << '\n';
else cout << "?\n";
}
# | 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... |