제출 #658408

#제출 시각아이디문제언어결과실행 시간메모리
658408FoxyyLogičari (COCI21_logicari)C++17
10 / 110
32 ms5748 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define Foxyy cin.tie(0); cout.sync_with_stdio(0); cout.tie(0); const int INF = 0x3f3f3f3f; struct Solver { int& n; vector<vector<int>>& adj; void solve() { int ans = INF; for (int mask = 2; mask < (1 << n); mask++) { if (__builtin_popcount(mask) % 2 != 0) continue; bool valid = true; for (int i = 0; i < n; i++) { int cnt = 0; for (int j : adj[i]) if ((mask >> j) & 1) { cnt++; } if (cnt != 1) { valid = false; break; } } if (valid) { ans = min(ans, __builtin_popcount(mask)); } } if (ans == INF) { cout << "-1\n"; } else { cout << ans << '\n'; } } }; signed main() { Foxyy int T = 1; // cin >> T; while(T--) { int n; cin >> n; vector<vector<int>> adj(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; a--, b--; adj[a].push_back(b); adj[b].push_back(a); } Solver solver{n, adj}; solver.solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...