제출 #1355179

#제출 시각아이디문제언어결과실행 시간메모리
1355179bimmerKOVANICE (COI15_kovanice)C++20
50 / 100
46 ms9116 KiB
#include <bits/stdc++.h>
#ifdef LOCAL
#include "algo/debug.h"
#endif
using namespace std;
#define int long long 
#define endl '\n'
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int sz = 3e5 + 5, inf = 1e9, mod = 998244353;

int ans[sz];
int par[sz];

int find(int a){
    if (par[a] < 0) return a;
    return par[a] = find(par[a]);
}

void unite(int a, int b){
    a = find(a);
    b = find(b);
    if (a != b) {
        if (par[a] > par[b]) swap(a, b);
        par[a] += par[b];
        par[b] = a;
    }
}

void _(){ 
    int n, m, v;
    cin >> n >> m >> v;
    for (int i = 1; i <= m; i++) par[i] = -1;
    vector<pair<int, int>> ed;
    for (int i = 1; i <= v; i++) {
        int a, b;
        char c;
        cin >> a >> c >> b;
        if (c == '<') {
            ed.push_back({a, b});
        } else {
            unite(a, b);
        }
    }
    for (auto [a, b] : ed) {
        a = find(a);
        b = find(b);
        if (a != b) {
            ans[a] = 1;
            ans[b] = 2;
        }
    }
    for (int i = 1; i <= m; i++) {
        int r = find(i);
        if (ans[r] == 0 or ans[r] == inf) ans[i] = inf;
        else ans[i] = ans[r];
        if (ans[i] == inf or ans[i] == 0) cout << "?\n";
        else cout << "K" << ans[i] << endl;
    }
}

signed main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    int T = 1;
    // cin >> T;
    while (T--) _();
}
// By Riyad
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...