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 main(){
ios::sync_with_stdio(0);cin.tie(0);
int x; cin>>x;
if(x>20){
cout<<(x%4?-1:x/2);
return 0;
}
vector<int>v[x];
for(int i=1;i<=x;i++){
int l,r;cin>>l>>r;
l--;r--;
v[l].push_back(r);
v[r].push_back(l);
}
int ans=1e9;
for(int i=1;i<(1<<x);i++){
bool f=1;
for(int j=0;j<x;j++){
int cnt=0;
for(auto c:v[j])
if(i&(1<<c))cnt++;
f&=(cnt==1);
}
if(f)
ans=min(ans,__builtin_popcount(i));
}
cout<<(ans==1e9?-1: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... |