답안 #933739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933739 2024-02-26T08:46:02 Z LucaIlie Political Development (BOI17_politicaldevelopment) C++17
0 / 100
134 ms 3192 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 ( j != -1 && ((mask >> j) & 1) )
                    vec++;
            }

            if ( vec != sz - 1 )
                ok = false;
        }
        if ( ok )
            ans = max( ans, sz );
    }
    for ( int i = 0; i < n; i++ )
        pos[vertices[i]] = -1;

    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;
    }
    for ( int i = 0; i < n; i++ )
        pos[i] = -1;

    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

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:45:15: warning: 'n' is used uninitialized in this function [-Wuninitialized]
   45 |     int n, k, minn = n;
      |               ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 3192 KB Output is correct
2 Incorrect 1 ms 3160 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3164 KB Output isn't correct
2 Halted 0 ms 0 KB -