답안 #880844

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880844 2023-11-30T07:04:01 Z vjudge1 Love Polygon (BOI18_polygon) C++17
0 / 100
139 ms 9736 KB
// in the name of God
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff first
#define ss second
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define mpp make_pair
#define ppb pop_back
#define endl '\n'
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O4")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9 + 9, maxn = 1e5 + 10, inf = 1e9 + 1, lg = 25, pp = 4447, modd = 1e9 + 9;

vector<int> out(maxn), c;
bool mark[maxn];
map<string, int> mp;
int n, pt, x, ans;

void dfs(int v){
	mark[v] = true;
	x++;
	if(!mark[out[v]]) dfs(out[v]);
}
signed main(){
	fast();
	cin >> n;
	for(int i = 0; i < n; ++i){
		string a, b; cin >> a >> b;
		if(!mp[a]) mp[a] = ++pt;
		if(!mp[b]) mp[b] = ++pt;
		out[mp[a] - 1] = mp[b] - 1;
	}
	if(n % 2) return cout << -1, 0;
	for(int i = 0; i < pt; ++i){
		if(!mark[i]){
			x = 0;
			dfs(i);
			c.pb(x);
		}
	}
	for(int i : c){
		if(i <= 2) continue;
		ans += ceil((double) i / 2);
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 139 ms 9736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -