제출 #404776

#제출 시각아이디문제언어결과실행 시간메모리
404776rama_pangPolitical Development (BOI17_politicaldevelopment)C++17
100 / 100
271 ms10604 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int N, K; cin >> N >> K; vector<int> deg(N); vector<vector<int>> adj(N); for (int u = 0; u < N; u++) { int sz; cin >> sz; while (sz--) { int v; cin >> v; deg[u]++; adj[u].emplace_back(v); } } vector<int> done(N); priority_queue<pair<int, int>> pq; for (int u = 0; u < N; u++) { sort(begin(adj[u]), end(adj[u])); pq.emplace(-deg[u], u); } int ans = 0; while (!pq.empty()) { int mn = pq.top().second; pq.pop(); if (done[mn]) { continue; } done[mn] = 1; static vector<int> ls; ls = {mn}; for (auto v : adj[mn]) if (!done[v]) { ls.emplace_back(v); deg[v]--; pq.emplace(-deg[v], v); } int n = ls.size(); assert(n <= K); static array<int, 10> arr; for (int i = 0; i < n; i++) { arr[i] = 1 << i; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int u = ls[i], v = ls[j]; if (binary_search(begin(adj[u]), end(adj[u]), v)) { arr[i] |= 1 << j; arr[j] |= 1 << i; } } } for (int mask = 1; mask < (1 << n); mask++) { int valid = mask; for (int i = 0; i < n; i++) if ((mask >> i) & 1) { valid &= arr[i]; } if (valid == mask) { ans = max(ans, __builtin_popcount(mask)); } } } cout << ans << '\n'; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...