답안 #880845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880845 2023-11-30T07:05:03 Z vjudge1 Love Polygon (BOI18_polygon) C++17
25 / 100
163 ms 9852 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 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 137 ms 9088 KB Output is correct
5 Correct 134 ms 9428 KB Output is correct
6 Correct 163 ms 9040 KB Output is correct
7 Correct 129 ms 8892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 139 ms 9852 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 -