#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);
}
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;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
21 ms |
6876 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
452 KB |
Output is correct |
2 |
Correct |
24 ms |
348 KB |
Output is correct |
3 |
Correct |
24 ms |
348 KB |
Output is correct |
4 |
Correct |
25 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
11 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
5 ms |
348 KB |
Output is correct |
9 |
Correct |
33 ms |
348 KB |
Output is correct |
10 |
Correct |
26 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
26 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
452 KB |
Output is correct |
2 |
Correct |
24 ms |
348 KB |
Output is correct |
3 |
Correct |
24 ms |
348 KB |
Output is correct |
4 |
Correct |
25 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
11 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
5 ms |
348 KB |
Output is correct |
9 |
Correct |
33 ms |
348 KB |
Output is correct |
10 |
Correct |
26 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
26 ms |
348 KB |
Output is correct |
13 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
21 ms |
6876 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |