제출 #1120715

#제출 시각아이디문제언어결과실행 시간메모리
1120715vjudge1KOVANICE (COI15_kovanice)C++17
10 / 100
2057 ms3284 KiB
#include <bits/stdc++.h>
#define GOOD_LUCK ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int	 long long
#define endl "\n"
#define MAX 10005	
#define INF 1000000000
#define MOD 16714589
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
using namespace std;

const int MAXN = 1e+5;

int temp;

signed main() {
	
	GOOD_LUCK
	
    int t;
	t = 1;
//	cin >> t;
    while (t--) {
		int n, k, w;
		cin >> k >> n >> w;
		vector <int> v(n+2, 0);
		vector <pair<int, int>> v1;
		for (int i=0; i < w; i++) {
			int x, y;
			char c;
			cin >> x >> c >> y;
			if (c == '>') {
				v[x] = 2;
				v[y] = 1;
			}
			else if (c == '<') {
				v[x] = 1;
				v[y] = 2;
			}
			else if (v[x] != 0) {
				v[y] = v[x];
			}
			else if (v[y] != 0) {
				v[x] = v[y];
			}
			else {
				v1.push_back({x, y});
			}
		}
		bool c = false;
		temp = 2*n-1;
		while (!c && temp) {
			c = true;
			for (auto i : v1) {
				if (v[i.ff] != 0 && v[i.ss] == 0) {
					v[i.ss] = v[i.ff];
				}
				if (v[i.ss] != 0 && v[i.ff] == 0) {
					v[i.ff] = v[i.ss];
				}
				else {
					c = false;
				}
			}
			temp--;
		}
		for (int i =1; i <= n; i++) {
			if (v[i] == 0) cout << "?\n";
			else {
				cout << "K" << v[i] << endl;
			}
		}
	}
	
    return 0;
}

// Problem B
// by Ekber_Ekber
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...