#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nl endl
#define hehe ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL) ;
// const int mod = 998244353;
const int mod = 1e9+7;
const int M = 2e5+5;
int count(int x){
int c = 0;
while(x){
x &= (x - 1);
c++;
}
return c;
}
void solve(){
int n; cin >> n;
int a[n+5] = {};
for(int i = 1; i<=n; i++){
int x,y; cin >> x >> y;
a[x]|= 1ll << (y-1);
a[y]|= 1ll << (x-1);
}
int tmp = LLONG_MAX;
for(int i = 0; i< (1 << n); i++) {
bool ok = true;
for (int j = 1; j<=n; j++) {
int t = a[j] & i;
int cnt = count(t);
if(cnt!=1){
ok = false;
break;
}
}
if(ok){
int cur = count(i);
if(cur < tmp) tmp = cur;
}
}
if(tmp == LLONG_MAX) cout << "-1" << nl;
else cout << tmp << nl;
}
signed main(){
hehe
// int t; cin >> t;
int t = 1;
while(t--){
solve();
}
}
# | 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... |