Submission #433794

# Submission time Handle Problem Language Result Execution time Memory
433794 2021-06-20T10:54:51 Z AmineWeslati Love Polygon (BOI18_polygon) C++14
0 / 100
275 ms 8876 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)

typedef string str; 

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)


void ckmin(int &x, int y){x=min(x,y);}
//------------------------------------


int main(){
	int N; cin>>N;

	if(N&1){
		cout << -1 << endl;
		return 0;
	}

	map<string,int>mp;
	int cnt=-1;
	vi nxt(N);
	FOR(i,0,N){
		str s,t; cin>>s>>t;
		if(!mp.count(s)) mp[s]=++cnt; 
		if(!mp.count(t)) mp[t]=++cnt; 
	
		int u=mp[s],v=mp[t];
		nxt[u]=v;
	}

	int ans=0;
	vi vis(N,0);
	FOR(i,0,N) if(!vis[i]){
		int n=0,cur=i;
		while(!vis[cur]){
			n++;
			vis[cur]=1;
			cur=nxt[cur];
		}
		ans+=(n+1)/2;
	}
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 275 ms 8876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -