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>
#define GOOD_LUCK ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"
#define MAX 10005
#define INF 1000000000
#define MOD 16714589
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
using namespace std;
const int MAXN = 1e+5;
int temp;
signed main() {
GOOD_LUCK
int t;
t = 1;
// cin >> t;
while (t--) {
int n, k, w;
cin >> k >> n >> w;
vector <int> v(n+2, 0);
vector <pair<int, int>> v1;
for (int i=0; i < w; i++) {
int x, y;
char c;
cin >> x >> c >> y;
if (c == '>') {
v[x] = 2;
v[y] = 1;
}
else if (c == '<') {
v[x] = 1;
v[y] = 2;
}
else if (v[x] != 0) {
v[y] = v[x];
}
else if (v[y] != 0) {
v[x] = v[y];
}
else {
v1.push_back({x, y});
}
}
bool c = false;
temp = v1.size()-1;
while (!c && temp) {
c = true;
for (auto i : v1) {
if (v[i.ff] != 0 && v[i.ss] == 0) {
v[i.ss] = v[i.ff];
}
if (v[i.ss] != 0 && v[i.ff] == 0) {
v[i.ff] = v[i.ss];
}
else {
c = false;
}
}
temp--;
}
for (int i =1; i <= n; i++) {
if (v[i] == 0) cout << "?\n";
else {
cout << "K" << v[i] << endl;
}
}
}
return 0;
}
// Problem B
// by Ekber_Ekber
# | 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... |