답안 #438112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
438112 2021-06-27T15:10:30 Z promg Planinarenje (COCI18_planinarenje) C++17
160 / 160
6 ms 640 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 5e3 + 5;
 
int n, m;
int mat[maxn];
vector<int> adj[maxn];
bitset<maxn> mark, fmat, ans;
 
bool dfs(int v){
	if (mark[v]) return false;
	mark[v] = true;
 
	for (auto u:adj[v])
		if (mat[u] == -1 || dfs(mat[u])){
			mat[u] = v;
			return true;
		}
	return false;
}
 
void dfs2(int v){
	if (mark[v]) return;
	mark[v] = true;
 
	for (auto u:adj[v])
		if (mat[u] != -1){
			ans[mat[u]] = true;
			dfs2(mat[u]);
		}
	return;
}
 
int main(){
	memset(mat, -1, sizeof(mat));
 
	cin >> n >> m;
	for (int i = 0, v, u; i < m; i++){
		cin >> v >> u; v--, u--;
		adj[v].push_back(u);
	}
 
	bool find = true;
	while (find){
		find = false;
		mark.reset();
		for (int i = 0; i < n; i++)
			if (!fmat[i] && dfs(i))
				fmat[i] = find = true;
	}
 
	mark.reset();
	for (int i = 0; i < n; i++)
		if (!fmat[i])
			dfs2(i);
 
	for (int i = 0; i < n; i++){
		if (!fmat[i] || ans[i])
			cout << "Mirko\n";
		else
			cout << "Slavko\n";
    }
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 432 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 428 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 588 KB Output is correct
2 Correct 6 ms 588 KB Output is correct
3 Correct 4 ms 640 KB Output is correct
4 Correct 5 ms 576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 5 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 4 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 460 KB Output is correct
2 Correct 5 ms 588 KB Output is correct
3 Correct 6 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 460 KB Output is correct
2 Correct 5 ms 588 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 5 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 532 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 5 ms 588 KB Output is correct
4 Correct 4 ms 440 KB Output is correct