답안 #303835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
303835 2020-09-20T16:50:25 Z shivensinha4 Planinarenje (COCI18_planinarenje) C++17
160 / 160
399 ms 1144 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'

vector<vi> adj;
vi match;

bool augmentingPath(int l, int r) {
	// l and r are the number of nodes on left and right side.
	// It will be assumed that nodes 0 -> l-1 are the ones on the left side and rest l -> l+r-1 on the right
	
	vi pre(l+r, -1);
	int end = -1;
	queue<int> q;
	for_(i, 0, l) if (match[i] == -1) {
		q.push(i);
		pre[i] = i;
	}
	while (q.size() and end == -1) {
		int p = q.front(); q.pop();
		bool right = p >= l;
		for (int i: adj[p]) if (pre[i] == -1 and match[i] != -2 and ((match[p] == i) == right)) {
			assert((i < l) ^ (p < l));
			pre[i] = p;
			// found an unmatched edge on the right side
			if (match[i] == -1)  {
				end = i;
				break;
			}
			q.push(i);
		}
	}
	
	if (end == -1) return false; // couln't find augmenting path
	
	// update the matching to include the flipped edges in the augmenting path
	int p = end;
	while (true) {
		if (pre[p] == p) break;
		match[p] = pre[p];
		match[pre[p]] = p;
		p = pre[pre[p]];
	}
	
	return 1;
}

int main() {
	#ifdef shiven
	freopen("test.in", "r", stdin);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m; cin >> n >> m;
	adj.resize(2*n); match.resize(2*n, -1);
	for_(i, 0, m) {
		int a, b; cin >> a >> b;
		a -= 1; b += n-1;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	int full = 0;
	while (true) {
		int v = augmentingPath(n, n);
		if (!v) break;
		full += v;
	}
	
	for_(i, 0, n) {
		bool first = true;
		if (match[i] == -1) first = false;
		else {
			vi prev = match;
			match[match[i]] = -1;
			match[i] = -2;
			if (augmentingPath(n, n)) first = false;
			
			match[i] = -1;
			swap(match, prev);
		}
		
		cout << (first ? "Slavko" : "Mirko") << endl;
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 309 ms 1016 KB Output is correct
2 Correct 396 ms 1144 KB Output is correct
3 Correct 342 ms 896 KB Output is correct
4 Correct 399 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 384 KB Output is correct
2 Correct 16 ms 492 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 640 KB Output is correct
2 Correct 279 ms 896 KB Output is correct
3 Correct 108 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 640 KB Output is correct
2 Correct 178 ms 908 KB Output is correct
3 Correct 57 ms 640 KB Output is correct
4 Correct 8 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 760 KB Output is correct
2 Correct 78 ms 640 KB Output is correct
3 Correct 167 ms 888 KB Output is correct
4 Correct 35 ms 512 KB Output is correct