답안 #227368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
227368 2020-04-27T07:49:22 Z mohammad_amin Planinarenje (COCI18_planinarenje) C++14
160 / 160
40 ms 3072 KB
#include <bits/stdc++.h>
using namespace std;

const int MN = 50012;
vector <int> adj[MN], kaj[MN];
int p[MN];
bool mark[MN];
int good[MN];

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

bool kfs(int v) {
//	cerr << v << endl;
	mark[v] = true;
	for (int u: kaj[v]) {
//		cerr << v << ' ' << u << ' ' << good[u] << endl;
		if ((good[u] == -1) || (!mark[good[u]] && kfs(good[u]))) {
//			cerr << v << '?' << u << '?' << good[u] << endl;
			return true;
		}
	}
	return false;
}

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		good[i] = p[i] = -1;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		adj[--a].push_back(--b);
		kaj[b].push_back(a);
	}
	for (int i = 0; i < n; i++) {
		for (int i = 0; i < n; i++)
			mark[i] = false;
		dfs(i);
	}
//	good[2] = -1;
//	cerr << (good[2] = -1) << '*' << endl;
	for (int i = 0; i < n; i++)
		if (p[i] != -1)
			good[p[i]] = i;//, cerr << p[i] << '=' << i << endl;
//	for (int i = 0; i < n; i++)
//		cerr << p[i] << '!' << ' ';
//	cerr << endl;
//	for (int i = 0; i < n; i++)
//		cerr << good[i] << '!' << ' ';
//	cerr << endl;
	for (int i = 0; i < n; i++) {
		for (int i = 0; i < n; i++)
			mark[i] = false;
		if (good[i] == -1)
			cout << "Mirko\n";
		else if (kfs(good[i]))	
			cout << "Mirko\n";
		else
			cout << "Slavko\n";			
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 7 ms 2688 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 2944 KB Output is correct
2 Correct 33 ms 2944 KB Output is correct
3 Correct 32 ms 2944 KB Output is correct
4 Correct 33 ms 3072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 2816 KB Output is correct
2 Correct 21 ms 2816 KB Output is correct
3 Correct 14 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2688 KB Output is correct
2 Correct 12 ms 2816 KB Output is correct
3 Correct 15 ms 2816 KB Output is correct
4 Correct 17 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 2816 KB Output is correct
2 Correct 33 ms 2944 KB Output is correct
3 Correct 16 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2816 KB Output is correct
2 Correct 23 ms 3032 KB Output is correct
3 Correct 13 ms 2816 KB Output is correct
4 Correct 35 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 2944 KB Output is correct
2 Correct 13 ms 2816 KB Output is correct
3 Correct 23 ms 2944 KB Output is correct
4 Correct 29 ms 2816 KB Output is correct