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;
typedef long long ll;
#define endl '\n'
void solve(){
int n;
cin>>n;
vector<vector<int>> adj(n);
for(int i=1;i<=n;i++){
int a,b;
cin>>a>>b;
a --, b --;
adj[a].push_back(b);
adj[b].push_back(a);
}
if(n <= 20){
int ans = 1e9;
for(int mask=0;mask<(1<<n);mask++){
bitset<21> on;
for(int i=0;i<n;i++) on[i] = (mask>>i)&1;
for(int i=0;i<n;i++){
int cnt = 0;
for(auto ch : adj[i]) cnt += on[ch];
if(cnt != 1) goto gt;
}
ans = min(ans,(int)on.count());
gt: continue;
}
cout<<(ans == 1e9 ? -1 : ans)<<endl;
}
else {
if(n%4 == 0) cout<<n/2<<endl;
else cout<<-1<<endl;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
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... |