Submission #764948

#TimeUsernameProblemLanguageResultExecution timeMemory
764948adrilenPolitical Development (BOI17_politicaldevelopment)C++17
100 / 100
257 ms30084 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using arr = array<int, 2>; constexpr int maxn = 5e4 + 5, maxk = 11; bool visited[maxn] = { 0 }; set<int> adj[maxn]; int k; int output = 1; void dfs(int pos) { // assert(!visited[pos]); assert((int)adj[pos].size() <= k); visited[pos] = true; vector <bitset<maxk>> v(adj[pos].size()); int ii = 0; // Counts which place it is in the order of adj[pos] int iii; for (int i : adj[pos]) { iii = 0; v[ii][ii] = true; for (int y : adj[pos]) { if (i != y) { v[ii][iii] = adj[i].count(y); } iii++; } ii++; } bitset<maxk> all; for (int i = 1; i < (1 << (adj[pos].size())); i++){ all.set(); for (size_t y = 0; y < adj[pos].size(); y++) { if (i & (1 << y)) all &= v[y]; } // cout << i << " " << all << "\n"; if (__builtin_popcount(i) == all.count()) output = max(output, __builtin_popcount(i) + 1); } for (int i : adj[pos]) adj[i].erase(pos); // Something with the deletion is fishy, since for (int i : adj[pos]) if (!visited[i] && (int)adj[i].size() <= k) dfs(i); // We need this !visited[i] } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n >> k; for (int i = 0; i < n; i++) { int a, b; cin >> a; for (int y = 0; y < a; y++) { cin >> b; adj[i].insert(b); } } for (int i = 0; i < n; i++) if (!visited[i] && (int)adj[i].size() <= k) dfs(i); cout << output << "\n"; // cerr << clock() / static_cast<double>(CLOCKS_PER_SEC) << "\n"; }
#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...