This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
vector<pair<int,int>> e;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 0;i<n;i++){
cin >> a >> b;e.push_back({a-1,b-1});
}
int ans = 100;
if (n > 20) {
if (n%4 == 0) cout << n/2;
else cout << -1;
return 0;
}
for (int mask = 0;mask<1<<n;mask++){
vector<int> cnt(n,0);
for (int i = 0;i<n;i++){
if ((1<<e[i].second)&mask) cnt[e[i].first]++;
if ((1<<e[i].first)&mask) cnt[e[i].second]++;
}
int pos = 1;
for (int i = 0;i<n;i++){
if (cnt[i] != pos){
pos = 0;
break;
}
}
if (pos) ans = min(ans,__popcount(mask));
}
if (ans == 100) ans = -1;
cout << ans;
return 0;
}
# | 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... |