제출 #1330987

#제출 시각아이디문제언어결과실행 시간메모리
1330987paronmanukyanKOVANICE (COI15_kovanice)C++20
100 / 100
161 ms36020 KiB
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniq(x) x.resize(unique(all(x)) - x.begin());
#define sort_uniq(x) sort(all(x)), uniq(x);
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define V vector
#define V2dll V<V<ll>>
#define V2dint V<V<int>>
#define V2dchar V<V<char>>
#define V2dbool V<V<bool>>
#define V3dll V<V<V<ll>>>
#define V3dint V<V<V<int>>>
#define V3dchar V<V<V<char>>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define FASTIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr);                                                            \
  cout.tie(nullptr);
#define INF INT32_MAX
#define blt __builtin_popcount
#define clr(x) x.clear()
#define ff first
#define ss second
#define popf pop_front
#define popb pop_back
#define sz(x) int(x.size())
#define rep(a, b, c, d) for (int a = b; a <= c; a += d)
#define repl(a, b, c, d) for (int a = b; a >= c; a -= d)

mt19937_64 rng(chrono::steady_clock().now().time_since_epoch().count());

const int N = 3e5 + 5;
V<int> adjb[N], adjs[N];
int p[N], s[N], bg[N], sm[N], ans[N];
bool v1[N], v2[N];

void init() {
    rep(i, 1, N - 1, 1) 
        p[i] = i, s[i] = 1;
}

int find(int x) {
    if (x == p[x]) return x;
    return p[x] = find(p[x]);
}

void merge(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return;
    if (s[a] < s[b])
        swap(a, b);

    s[a] += s[b];
    p[b] = a;
    return;
}

void dfs1(int node) {
    v1[node] = true;
    for (auto i : adjb[node]) {
        if (!v1[i])
            dfs1(i);
        bg[node] = max(bg[node], bg[i] + 1);
    }
}

void dfs2(int node) {
    v2[node] = true;
    for (auto i : adjs[node]) {
        if (!v2[i])
            dfs2(i);
        sm[node] = max(sm[node], sm[i] + 1);
    }
}

int main()
{
	FASTIO
    init();
	int n, m, q; cin >> n >> m >> q;
    rep(i, 1, m, 1)
        ans[i] = -1;
    V<pii> eq, bigg;
    rep(i, 1, q, 1) {
        int a, b; char c;
        cin >> a >> c >> b;
        if (c == '=')
            eq.pb({a, b});
        else {
            if (c == '<')
                swap(a, b);
            bigg.pb({a, b});
        }
    }
    for (auto [a, b] : eq) {
        //cout << a << " " << b << endl;
        merge(a, b);
    }
        

    //rep(i, 1, m, 1) 
    //    cout << find(i) << " ";
    for (auto [a, b] : bigg) {
        adjb[find(a)].pb(find(b));
        adjs[find(b)].pb(find(a));
    }
    rep(i, 1, m, 1) {
        if (!v1[i]) 
            dfs1(i);
    }
    rep(i, 1, m, 1) {
        if (!v2[i])
            dfs2(i);
    }
    rep(i, 1, m, 1) {
        if (bg[i] + sm[i] == n - 1) {
            ans[i] = bg[i] + 1;
        }
    }
    rep(i, 1, m, 1) {
        ans[i] = ans[find(i)];
    }
    rep(i, 1, m, 1) {
        if (ans[i] == -1) {
            cout << "?\n";
            continue;
        }
        cout << 'K' << ans[i] << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...