제출 #846236

#제출 시각아이디문제언어결과실행 시간메모리
846236vjudge1KOVANICE (COI15_kovanice)C++17
50 / 100
514 ms17064 KiB
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PB push_back
#define POB pop_back
#define ordered_set                              \
    tree<int, null_type, less<int>, rb_tree_tag, \
         tree_order_statistics_node_update>
#define int int64_t
#define F first
#define S second
#define I insert
#define sqr(a) ((a) * (a))
#define P pop
#define max3(a, b, c) (max(a, max(b, c)))
#define max4(a, b, c, d) (max(max(a, b), max(c, d)))
#define min3(a, b, c) (min(a, min(b, c)))
#define min4(a, b, c, d) (min(min(a, b), min(c, d)))
#define MOD 1000000007
#define mod 998244353
int binpow(int a, int p, int m = MOD) {
    int ans = 1;
    while (p) {
        if (p & 1) ans = ((ans % m) * (a % m)) % m;
        a = sqr(a) % m;
        p >>= 1;
    }
    return ans;
}
void solve() {
    int n, m, v;
    cin >> n >> m >> v;
    vector<vector<int>> adj(m, vector<int>());
    vector<int> typ(m, 0);
    queue<int> q;
    for (int i = 0; i < v; i++) {
        int a, c;
        char b;
        cin >> a >> b >> c;
        if (b == '=') {
            adj[a - 1].PB(c - 1);
            adj[c - 1].PB(a - 1);
        }
        if (b == '<') {
            typ[a - 1] = 1;
            typ[c - 1] = 2;
        }
        if (b == '>') {
            typ[a - 1] = 2;
            typ[c - 1] = 1;
        }
    }
    vector<bool> vis(m, false);
    for (int i = 0; i < m; i++) {
        if (typ[i] != 0) {
            q.push(i);

        }
    }
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (auto x : adj[u]) {
            if (vis[x]) continue;
            typ[x] = typ[u];
            vis[x] = true;
            q.push(x);
        }
    }
    for (int i = 0; i < m; i++) {
        if (typ[i] == 0)
            cout << '?' << endl;
        else if (typ[i] == 1)
            cout << "K1" << endl;
        else
            cout << "K2" << endl;
    }
}
int32_t main() {
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...