Submission #227346

# Submission time Handle Problem Language Result Execution time Memory
227346 2020-04-27T05:57:11 Z aarr Planinarenje (COCI18_planinarenje) C++14
160 / 160
278 ms 888 KB
#include <iostream>
#include <vector>
using namespace std;

const int N = 5005;

vector <int> adj[N];
bool mark[N];
int mt1[N];
int mt2[N];

bool dfs(int v) {
	mark[v] = true;
	for (auto u : adj[v]) {
		if (!mt2[u] || (!mark[mt2[u]] && dfs(mt2[u]))) {
			mt2[u] = v;
			mt1[v] = u;
			return true;
		}
	}
	return false;
}

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
	}
	bool b = true;
	while (b) {
		fill(mark, mark + n + 1, false);
		b = false;
		for (int i = 1; i <= n; i++) {
			if (!mt1[i] && !mark[i] && dfs(i)) {
				b = true;
			}
		}
	//	cout << 47 << endl;
	}
/*	cout << 48 << endl;
	for (int i = 1; i <= n; i++) {
		cout << "49 " << i << " " << mt1[i] << endl;
	}*/
	for (int i = 1; i <= n; i++) {
		if (!mt1[i]) {
			cout << "Mirko" << endl;
		}
		else {
			fill(mark, mark + n + 1, false);
			bool b = false;
			mt2[mt1[i]] = 0;
			for (int j = 1; j <= n; j++) {
				if (j != i && !mark[j] && !mt1[j] && dfs(j)) {
					b = true;
				} 
			}
			if (b) {
				mt1[i] = 0;
				cout << "Mirko" << endl;
			}
			else {
				mt2[mt1[i]] = i;
				cout << "Slavko" << endl;
			}
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 8 ms 512 KB Output is correct
4 Correct 8 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 267 ms 692 KB Output is correct
2 Correct 273 ms 640 KB Output is correct
3 Correct 239 ms 772 KB Output is correct
4 Correct 278 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 512 KB Output is correct
2 Correct 10 ms 512 KB Output is correct
3 Correct 9 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 512 KB Output is correct
2 Correct 21 ms 512 KB Output is correct
3 Correct 9 ms 512 KB Output is correct
4 Correct 9 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 512 KB Output is correct
2 Correct 174 ms 888 KB Output is correct
3 Correct 65 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 512 KB Output is correct
2 Correct 107 ms 632 KB Output is correct
3 Correct 61 ms 632 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 512 KB Output is correct
2 Correct 71 ms 512 KB Output is correct
3 Correct 99 ms 632 KB Output is correct
4 Correct 34 ms 512 KB Output is correct