Submission #303832

# Submission time Handle Problem Language Result Execution time Memory
303832 2020-09-20T16:48:39 Z shivensinha4 Planinarenje (COCI18_planinarenje) C++17
160 / 160
459 ms 1144 KB
#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;
			//cout << "no match initially" << endl;
		}
		else {
			vi prev = match;
			match[match[i]] = -1;
			match[i] = -2;
			bool red = false;
			if (augmentingPath(n, n)) {
				first = false;
				red = true;
			}
			
			match[i] = -1;
			swap(match, prev);
		}
		
		cout << (first ? "Slavko" : "Mirko") << endl;
	}

	return 0;
}

Compilation message

planinarenje.cpp: In function 'int main()':
planinarenje.cpp:87:9: warning: variable 'red' set but not used [-Wunused-but-set-variable]
   87 |    bool red = false;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 345 ms 1016 KB Output is correct
2 Correct 446 ms 1024 KB Output is correct
3 Correct 391 ms 1016 KB Output is correct
4 Correct 459 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 512 KB Output is correct
2 Correct 5 ms 572 KB Output is correct
3 Correct 8 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 384 KB Output is correct
2 Correct 18 ms 512 KB Output is correct
3 Correct 9 ms 512 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 512 KB Output is correct
2 Correct 321 ms 1144 KB Output is correct
3 Correct 128 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 640 KB Output is correct
2 Correct 206 ms 888 KB Output is correct
3 Correct 63 ms 640 KB Output is correct
4 Correct 11 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 760 KB Output is correct
2 Correct 82 ms 640 KB Output is correct
3 Correct 192 ms 888 KB Output is correct
4 Correct 40 ms 632 KB Output is correct