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<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int main(){
int n;
cin>>n;
vector<vector<int>> graph(n);
int a,b;
for(int i=0;i<n;i++){
cin>>a>>b;
graph[a-1].push_back(b-1);
graph[b-1].push_back(a-1);
}
if(n<=20){
int ans=1e9;
for(int i=0;i<(1<<n);i++){
for(int j=0;j<n;j++){
int cnt=0;
for(auto x:graph[j]){
if(((1<<x)&i)>0){
cnt++;
}
}
if(cnt!=1) break;
if(j==n-1){
cnt=0;
for(int k=0;k<n;k++){
if(((1<<k)&i)>0) cnt++;
}
ans=min(ans,cnt);
}
}
}
if(ans==1e9) cout<<-1<<"\n";
else cout<<ans<<"\n";
return 0;
}
if(n%4==0) cout<<n/2;
else cout<<-1;
}
# | 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... |