답안 #909453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909453 2024-01-17T08:16:13 Z shoryu386 Love Polygon (BOI18_polygon) C++17
0 / 100
268 ms 23120 KB
#include <bits/stdc++.h>
using namespace std;
#define MAX 200007
#define int long long
main(){
	int n; cin >> n;
	
	if (n % 2 == 1) {cout << -1; return 0;}
	
	map<string, string> init;
	map<string, int> indexed;
	
	int adj[n];
	for (int x = 0; x < n; x++){
		string a, b; cin >> a >> b;
		
		init[a] = b;
	}
	
	string name[n]; int ptr = 0;
	for (auto y : init){
		name[ptr] = y.first;
		indexed[y.first] = ptr;
		ptr++;
	}
	
	for (auto y : init){
		adj[indexed[y.first]] = indexed[y.second];
	}
	
	bitset<MAX> taken;
	int ans = 0;
	
	for (int x = 0; x < n; x++){
		if (adj[x] != x && x == adj[adj[x]]){
			taken[x] = 1;
			taken[adj[x]] = 1;
		}
	}
	
	for (int x = 0; x < n; x++){
		if (taken[adj[x]]) {adj[x] = x; continue;}
	}
	
	for (int x = 0; x < n; x++){
		if (adj[x] == x) continue;
		if (taken[x]) continue;
		if (taken[adj[x]]) {adj[x] = x; continue;}
		adj[adj[x]] = x;
		ans++;
		taken[x] = 1;
		taken[adj[x]] = 1;
	}
	
	for (int x = 0; x < n; x++) if (!taken[x]) ans++;
	
	cout << ans;
}

Compilation message

polygon.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    5 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 268 ms 22900 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 239 ms 23120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -