# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
933736 | 2024-02-26T08:42:45 Z | LucaIlie | Political Development (BOI17_politicaldevelopment) | C++17 | 2 ms | 3164 KB |
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5e4; const int MAX_K = 10; int perm[MAX_N], pos[MAX_N]; unordered_set<int> adj[MAX_N]; int solve( vector<int> vertices ) { int n = vertices.size(); for ( int i = 0; i < n; i++ ) pos[vertices[i]] = i; int ans = 0; for ( int mask = 0; mask < (1 << n); mask++ ) { int sz = __builtin_popcount( mask ); bool ok = true; for ( int i = 0; i < n; i++ ) { if ( ((mask >> i) & 1) == 0 ) continue; int u = vertices[i]; int vec = 0; for ( int v: adj[u] ) { int j = pos[v]; if ( (mask >> j) & 1 ) vec++; } if ( vec != sz - 1 ) ok = false; } if ( ok ) ans = max( ans, sz ); } return ans; } int main() { int n, k, minn = n; cin >> n >> k; for ( int u = 0; u < n; u++ ) { int d; cin >> d; for ( int j = 0; j < d; j++ ) { int v; cin >> v; adj[u].insert( v ); } minn = min( minn, d ); perm[u] = u; } int ans = 0; for ( int i = 0; i < n; i++ ) { /*sort( perm + i, perm + n, []( int u, int v ) { return adj[u].size() < adj[v].size(); } );*/ int u = perm[i]; vector<int> vertices; vertices.push_back( u ); for ( int v: adj[u] ) { //adj[v].erase( u ); vertices.push_back( v ); } ans = max( ans, solve( vertices ) ); //adj[u].clear(); } vector<int> vertices; for ( int i = n - k; i < n; i++ ) { vertices.push_back( perm[i] ); } ans = max( ans, solve( vertices ) ); cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3164 KB | Output is correct |
2 | Incorrect | 1 ms | 2944 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3164 KB | Output is correct |
2 | Incorrect | 1 ms | 2944 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3164 KB | Output is correct |
2 | Incorrect | 1 ms | 3164 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3164 KB | Output is correct |
2 | Incorrect | 1 ms | 2944 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3164 KB | Output is correct |
2 | Incorrect | 1 ms | 2944 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |