Submission #1318454

#TimeUsernameProblemLanguageResultExecution timeMemory
1318454nnargizKOVANICE (COI15_kovanice)C++20
0 / 100
551 ms96584 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
const int mod = 1e6 + 3;
const int inf = 1e9;
const int maxx = 3e6 + 5;
const int lg = 26;
typedef tree <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

int tmr = 0;
set <pair <int, int> > s;
vector <int> g1[maxx], g2[maxx], dis(maxx), col(maxx, -1);

void dfs1(int u) {
    if (col[u] != -1) {
        return;
    }
    tmr++;
    col[u] = tmr;
    for (auto to : g1[u]) {
        dfs1(to);
    }
}

void dfs2(int u, int tmr) {
    if (col[u] != -1) {
        return;
    }
    col[u] = tmr;
    for (auto to : g2[u]) {
        dfs2(to, tmr);
    }
}

void solve () {
    int n, m, v;
    cin >> n >> m >> v;
    while (v--) {
        int a, b;
        char c;
        cin >> a >> c >> b;
        if (c == '=') {
            g2[a].push_back(b);
            g2[b].push_back(a);
            s.insert({a, b});
            s.insert({b, a});
        }
        else {
            g1[a].push_back(b);
            s.insert({a, b});
        }
    }
    for (int i = 1; i <= m; i++) {
        if (col[i] == -1) {
            if (!g2[i].empty()) {
                tmr++;
                dfs2(i, tmr);
            }
            else {
                dfs1(i);
            }
        }
    }
    for (int i = 1; i <= m; i++) {
        if (col[i] > n) {
            cout << '?' << endl;
        }
        else {
            cout << 'K' << col[i] << endl;
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    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...