Submission #1337755

#TimeUsernameProblemLanguageResultExecution timeMemory
1337755vache_kocharyanKOVANICE (COI15_kovanice)C++20
100 / 100
411 ms24984 KiB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const bool debug = true;

#define ff first
#define ss second
#define yes cout << "Yes\n"
#define no cout << "No\n"
#define YN(x) if(x)yes; else no;
#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()

const int mod = 1e9 + 7;

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x <<" "; print(x); cerr << endl;
#else
#define dbg(x)
#endif

void print(long long t) { cerr << t; }
void print(int t) { cerr << t; }
void print(string t) { cerr << t; }
void print(char t) { cerr << t; }
void print(double t) { cerr << t; }
void print(long double t) { cerr << t; }
void print(unsigned long long t) { cerr << t; }

template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T, class V> void print(T v[], V n) { cerr << "["; for (int i = 0; i < n; i++) { cerr << v[i] << " "; } cerr << "]"; }
template <class T, class V> void print(pair <T, V> p) { cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}"; }
template <class T> void print(vector <T> v) { cerr << "[ "; for (T i : v) { print(i); cerr << " "; } cerr << "]"; }
template <class T> void print(set <T> v) { cerr << "[ "; for (T i : v) { print(i); cerr << " "; } cerr << "]"; }
template <class T> void print(multiset <T> v) { cerr << "[ "; for (T i : v) { print(i); cerr << " "; } cerr << "]"; }
template <class T, class V> void print(map <T, V> v) { cerr << "[ "; for (auto i : v) { print(i); cerr << " "; } cerr << "]"; }
template <class T> void print(queue <T> q) { cerr << "[ "; while (!q.empty()) { print(q.front()); cerr << " "; q.pop(); } cerr << "]"; }
template <class T> void print(priority_queue <T> q) { cerr << "[ "; while (!q.empty()) { print(q.top()); cerr << " "; q.pop(); } cerr << "]"; }
template <class T> void print(int n__, T arr[]) { cerr << "[ "; for (int i = 0; i <= n__; i++) { print(arr[i]); cerr << " "; } cerr << "]"; }

ll gcdll(ll a, ll b) { return b == 0 ? a : gcdll(b, a % b); }

long long mult(long long a, long long b)
{
	return (a * b) % mod;
}

long long binpow(long long a, long long b) {
	long long res = 1;
	a %= mod;
	while (b > 0) {
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

long long m_inverse(long long n) {
	return binpow(n, mod - 2);
}

long long divide(long long a, long long b) {
	return (a % mod * m_inverse(b)) % mod;
}

long long sub(long long a, long long b)
{
	if (a - b >= 0)return a - b;
	else return a - b + mod;
}

long long add(long long a, long long b)
{
	if (a + b >= mod)return a + b - mod;
	else return a + b;
}

const int LOG = 64;
const int N = 3e5 + 5;
const ll inf = 1e18;

vector<int>adj[N];
int comp[N];
bool used[N];
bool vis[N];
int in[N];
int dp[N][2];
int c;

struct edge
{
	int a, b;
	char c;
}e[N];

void dfs_comp(int node)
{
	used[node] = true;
	comp[node] = c;
	for (auto i : adj[node]) {
		if (used[i])continue;
		dfs_comp(i);
	}
}

void dfs_dp(int node, int t) {
	vis[node] = true;
	for (auto i : adj[node]) {
		if (!vis[i])dfs_dp(i, t);
		dp[node][t] = max(dp[node][t], dp[i][t]);
	}
	dp[node][t]++;
}
void solve()
{
	int n, m, v;
	cin >> n >> m >> v;

	for (int i = 1; i <= v; i++)
	{
		int a, b;
		char c;
		cin >> a >> c >> b;
		
		if (c == '<')swap(a, b);
		e[i] = { a, b, c };
		if (c == '=')
		{
			adj[a].push_back(b);
			adj[b].push_back(a);
		}
	}
	c = 1;
	for (int i = 1; i <= m; i++) {
		if (!used[i]) {
			dfs_comp(i);
			c++;
		}
	}

	for (auto i = 1; i <= m; i++)adj[i].clear();
	for (int i = 1; i <= v; i++) {
		if (e[i].c != '=') {
			adj[comp[e[i].a]].push_back(comp[e[i].b]);
		}
	}
	for (int i = 1; i < c; i++) {
		if (!vis[i])
			dfs_dp(i, 0);
	}

	for (auto i = 1; i <= m; i++)
	{
		adj[i].clear(); vis[i] = false; in[i] = 0;
	}
	for (int i = 1; i <= v; i++) {
		if (e[i].c != '=') {
			adj[comp[e[i].b]].push_back(comp[e[i].a]);
		}
	}
	for (int i = 1; i < c; i++) {
		if (!vis[i] && in[i] == 0)
			dfs_dp(i, 1);
	}

	for (int i = 1; i <= m; i++) {
		if (dp[comp[i]][0] + dp[comp[i]][1] == (n + 1))
			cout << "K" << dp[comp[i]][0] << endl;
		else
			cout << "?" << endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...