제출 #861935

#제출 시각아이디문제언어결과실행 시간메모리
861935HossamHero7Logičari (COCI21_logicari)C++14
20 / 110
30 ms7056 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...