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 F first
#define S second
#define pb push_back
#define endl '\n'
#define all(x) x.begin(),x.end()
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
const int N = 1000,mod = 1e9+7;
vector<int>adj[N];
bool blue[N];
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
for(int i = 0;i<n;i++)
{
int a,b;
cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
int ans = 1e9;
for(int mask = 0;mask< (1<<n) ;mask++)
{
for(int i = 1;i<=n;i++)blue[i] = 0;
int cur = 0;
bool tr = 1;
for(int i = 0;i<n;i++)
{
if(mask&(1<<i))
blue[i+1] = 1,cur++;
}
for(int i = 1;i<=n;i++)
{
int cnt = 0;
for(auto u:adj[i])
cnt+=blue[u];
if(cnt!=1)
tr = 0;
}
if(tr)
ans = min(ans,cur);
}
if(ans==1e9)
cout<<-1<<endl;
else cout<<ans<<endl;
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... |