Submission #916605

# Submission time Handle Problem Language Result Execution time Memory
916605 2024-01-26T07:01:01 Z LCJLY Love Polygon (BOI18_polygon) C++14
25 / 100
286 ms 19028 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl; 
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;

vector<int>adj[100005];
map<string,int>mp;
int ptr=0;
int sz=0;
bool visited[100005];

void dfs(int index){
	sz++;
	visited[index]=true;
	for(auto it:adj[index]){
		if(visited[it]) continue;
		dfs(it);
	}
}

void solve(){
	int n;
	cin >> n;
	string s,s2;
	for(int x=0;x<n;x++){
		cin >> s >> s2;
		if(mp.find(s)==mp.end()){
			mp[s]=ptr++;
		}
		if(mp.find(s2)==mp.end()){
			mp[s2]=ptr++;
		}
		adj[mp[s]].push_back(mp[s2]);
		adj[mp[s2]].push_back(mp[s]);
	}
	
	int counter=0;
	for(int x=0;x<ptr;x++){
		if(visited[x]) continue;
		sz=0;
		dfs(x);
		if(sz==2) continue;
		counter+=(sz+1)/2;
	}
	if(ptr%2) cout << -1;
	else cout << counter;
}

int32_t main(){										
	ios::sync_with_stdio(0);	
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Incorrect 1 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 264 ms 18504 KB Output is correct
5 Correct 194 ms 15780 KB Output is correct
6 Correct 211 ms 19028 KB Output is correct
7 Correct 286 ms 17348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 197 ms 14048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Incorrect 1 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -