답안 #112866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112866 2019-05-22T09:20:27 Z mohammadrobot Planinarenje (COCI18_planinarenje) C++17
160 / 160
4 ms 768 KB
/* 
	بسم الله الرحمن الرحیم
	
	(; طلا یک جهانی
*/	

#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 5000 + 5;
int n, m, mch[MAX_N];
bool mark[MAX_N], mch_mark[MAX_N];
vector<int> adj[MAX_N];

void read_input() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
	}
}

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

void solve() {
	memset(mch, -1, sizeof mch);
	for (bool check = true; check; memset(mark, 0, sizeof mark)) {
		check = false;
		for (int i = 0; i < n; i++)
			if (!mark[i] && !mch_mark[i])
				check |= dfs(i);
	}
	for (int i = 0; i < n; i++)
		if (!mch_mark[i])
			dfs(i);
}

void print_output() {
	for (int i = 0; i < n; i++)
		if (mark[i])
			cout << "Mirko\n";
		else
			cout << "Slavko\n";
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	read_input();
	solve();
	print_output();
}

Compilation message

planinarenje.cpp: In function 'bool dfs(int)':
planinarenje.cpp:28:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if (!~mch[u] || !mark[mch[u]] && dfs(mch[u])) {
                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 768 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 4 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct