Submission #227354

# Submission time Handle Problem Language Result Execution time Memory
227354 2020-04-27T06:20:33 Z BRs82 Planinarenje (COCI18_planinarenje) C++14
160 / 160
8 ms 896 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
vector<int> gr[N];
int matchup[N], matchdw[N], n, m;
bool ans[N], mark[N];
bool dfs(int v) {
	mark[v] = 1;
	for (auto u : gr[v]) {
		if (matchup[u] == -1 || (!mark[matchup[u]] && dfs(matchup[u]))) {
			matchup[u] = v;
			matchdw[v] = u;
			return true;
		}
	}
	return false;
}
void getCmp(int v) {
	mark[v] = 1;
	for (auto u : gr[v]) {
		if (!mark[matchup[u]])
			getCmp(matchup[u]);
	}
	return;
}
int main() {
	ios_base::sync_with_stdio (false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		gr[x].push_back(y);
	}
	memset(matchup, -1, sizeof(matchup));
	memset(matchdw, -1, sizeof(matchdw));
	while (true) {
		bool z = false;
		for (int i = 0; i < n; i++) {
			if (!mark[i] && matchdw[i] == -1 && dfs(i)) {
				z = true;
			}
		}
		if (!z)
			break;
		memset(mark, 0, sizeof(mark));
	}
/*	memset(mark, 0, sizeof(mark));
	for (int i = 0; i < n; i++) {
		if (matchdw[i] == -1) {
			getCmp(i);
		}
	}*/
	for (int i = 0; i < n; i++) {
		if (mark[i])
			cout << "Mirko\n";
		else
			cout << "Slavko\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 896 KB Output is correct
2 Correct 7 ms 896 KB Output is correct
3 Correct 6 ms 896 KB Output is correct
4 Correct 6 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 768 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 768 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct