Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define forr(i, a, b) for(int i=(int)(a);i<(int)(b);i++)
- #define forn(i,n) forr(i,0,n)
- #define dforn(i,n) for(int i=(int)(n-1);i>=0;i--)
- #define forall(it, v) for(auto it=v.begin();it!=v.end();it++)
- #define pb push_back
- typedef long long ll;
- const int MAXN=100050;
- int n;
- pair<int,int> W[MAXN];
- map<int,int> M;
- int check(int t){
- int g=0;
- forn(i,n){
- if(W[i].first==t)g++;
- }
- int ans=0;
- forn(i,n){
- if(W[i].first==t) continue;
- if(g*2>=n) continue;
- if(W[i].second==t){g++;ans++;}
- }
- return g*2>=n?ans:n+1;
- }
- int main() {
- //~ freopen("D.in", "r", stdin);
- while(scanf("%d",&n)>=1){
- M.clear();
- forn(i,n){
- int a,b;
- scanf("%d%d",&a,&b);
- W[i]=make_pair(a,b);
- if(a==b){
- M[a]++;
- } else {
- M[a]++;
- M[b]++;
- }
- }
- vector<pair<int,int>> V;
- for(auto it:M){
- V.pb(make_pair(it.second,it.first));
- }
- sort(V.begin(),V.end());
- reverse(V.begin(),V.end());
- int t=min(10,(int)V.size());
- int ans=n+1;
- forn(i,t){
- ans=min(ans,check(V[i].second));
- }
- printf("%d\n",ans==n+1?-1:ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement