Submission #330220

# Submission time Handle Problem Language Result Execution time Memory
330220 2020-11-24T07:29:48 Z dolphingarlic KOVANICE (COI15_kovanice) C++14
100 / 100
250 ms 28764 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int cmp[300001];
vector<int> graph[300001];
int depth[300001], known[300001];

int find(int A) {
	while (A != cmp[A]) cmp[A] = cmp[cmp[A]], A = cmp[A];
	return A;
}

void onion(int A, int B) { cmp[find(A)] = find(B); }

void depth_dfs(int node) {
	depth[node] = 1;
	for (int i : graph[node]) {
		if (!depth[i]) depth_dfs(i);
		depth[node] = max(depth[node], depth[i] + 1);
	}
}

void known_dfs(int node) {
	known[node] = depth[node];
	for (int i : graph[node]) {
		if (!known[i] && depth[i] == depth[node] - 1) known_dfs(i);
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m, v;
	cin >> n >> m >> v;
	iota(cmp + 1, cmp + m + 1, 1);
	vector<pair<int, int>> edges;
	while (v--) {
		int a, b;
		char c;
		cin >> a >> c >> b;
		if (c == '=') onion(a, b);
		else if (c == '<') edges.push_back({b, a});
		else edges.push_back({a, b});
	}
	for (pair<int, int> i : edges) graph[find(i.first)].push_back(find(i.second));
	for (int i = 1; i <= m; i++) if (i == find(i) && !depth[i]) depth_dfs(i);
	for (int i = 1; i <= m; i++) if (i == find(i) && depth[i] == n) known_dfs(i);
	for (int i = 1; i <= m; i++) {
		if (known[find(i)]) cout << 'K' << known[find(i)] << '\n';
		else cout << "?\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7404 KB Output is correct
2 Correct 6 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 13292 KB Output is correct
2 Correct 80 ms 13420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 9576 KB Output is correct
2 Correct 25 ms 9576 KB Output is correct
3 Correct 26 ms 9448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 21604 KB Output is correct
2 Correct 201 ms 21476 KB Output is correct
3 Correct 189 ms 21256 KB Output is correct
4 Correct 206 ms 23516 KB Output is correct
5 Correct 250 ms 28764 KB Output is correct