이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define MAX 200007
#define int long long
bitset<MAX> visited;
int curSz = 0;
void dfs(int x, int adj[]){
	if (visited[x]) return;
	
	curSz++;
	visited[x] = 1;
	dfs(adj[x], adj);
}
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++;
	}
	
	int indeg[n]; memset(indeg, 0, sizeof(indeg));
	for (auto y : init){
		adj[indexed[y.first]] = indexed[y.second];
		if (y.first != y.second) indeg[indexed[y.second]]++;
	}
	
	bitset<MAX> taken;
	queue<int> process;
	for (int x = 0; x < n; x++){
		if (indeg[x] == 0) process.push(x);
		
		if (x != adj[x] && adj[adj[x]] == x) taken[x] = 1, taken[adj[x]] = 1;
	}
	
	int ans = 0;
	while (!process.empty()){
		int x = process.front();
		process.pop();
		
		if (taken[x]) continue;
		
		if (taken[adj[x]]){
			adj[x] = x;
			//indeg decrease, but doesn't matter since already taken
			continue;
		}
		
		ans++;
		indeg[adj[adj[x]]]--;
		if (indeg[adj[adj[x]]] == 0) process.push(adj[adj[x]]);
		
		adj[adj[x]] = x;
		
		taken[x] = 1;
		taken[adj[x]] = 1;
	}
	
	for (int x = 0; x < n; x++){
		if (!taken[x]){
			curSz = 0;
			dfs(x, adj);
			
			ans += (curSz+1)/2;
		}
	}
	
	cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
polygon.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   16 | main(){
      | ^~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |