Submission #862850

# Submission time Handle Problem Language Result Execution time Memory
862850 2023-10-19T06:11:04 Z maks007 Love Polygon (BOI18_polygon) C++14
25 / 100
229 ms 22100 KB
//Bismi Allah
#include "bits/stdc++.h"

using namespace std;

signed main () {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	map <string,int> mp;
	vector <int> used(n, 0), rk(n, 0), g[n];
	function <void(int)> dfs=[&](int v) {
		used[v] = 1;
		rk[v] = 1;
		for(auto u : g[v]) {
			if(used[u]) continue;
			dfs(u);
			rk[v] += rk[u];	
		}
	};
	for(int i = 0; i < n; i ++) {
		string u, v;
		cin >> u >> v;
		if(mp.count(u) == 0) mp[u] = mp.size();
		if(mp.count(v) == 0) mp[v] = mp.size();
		g[mp[u]].push_back(mp[v]);
		g[mp[v]].push_back(mp[u]);
	}
	if(n % 2 == 1) {
	//	assert(false);
		cout << -1;
		return 0;
	}
	int ans = 0, mod = 0;
	for(int i = 0; i < n; i ++) {
		if(used[i]) continue;
		dfs(i);
		if(rk[i] == 2) continue;
		ans += rk[i] / 2;
		mod += (rk[i] % 2);
	}
	if(mod % 2 == 1) cout << -1;
	else cout << ans + mod;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 206 ms 21240 KB Output is correct
5 Correct 199 ms 14420 KB Output is correct
6 Correct 210 ms 22100 KB Output is correct
7 Correct 229 ms 14532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 195 ms 14420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -