답안 #651248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
651248 2022-10-18T03:30:12 Z dooompy Political Development (BOI17_politicaldevelopment) C++17
0 / 100
8 ms 1908 KB
#include <bits/stdc++.h>

using namespace std;

int deg[50005];
vector<int> adj[50005];

set<pair<int, int>> s;
vector<int> neighbours;

bool erased[50005];

int ans = 0;
int sz;

bool check(int mask) {
    for (int i = 0; i < sz; i++) {
        if ((1 << i) & mask) {
            for (int j = 0; j < i; j++) {
                if (( 1 << j ) & mask) {
                    int a = neighbours[i], b = neighbours[j];

                    if (*lower_bound(adj[a].begin(), adj[a].end(), b) != b) return false;
                }
            }
        }
    }

    return true;
}

int main() {
    int n, k; cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> deg[i];
        s.insert({deg[i], i});

        for (int _ = 0; _ < deg[i]; _++) {
            int to; cin >> to;
            adj[i].push_back(to);
        }

        sort(adj[i].begin(), adj[i].end());
    }

    for (int i = 0; i < n; i++) {
        auto cur = *s.begin();
        s.erase(s.begin());

        if (cur.first == 0) {
            erased[cur.second] = true;
            continue;
        }

        neighbours.clear();
        neighbours.push_back(cur.second);
        for (auto nxt : adj[cur.second]) {
            if (erased[nxt]) continue;
            neighbours.push_back(nxt);
        }

        sz = neighbours.size();

        for (int mask = (1 << sz) - 1; mask >= (1 << ans); mask--) {
            if (__builtin_popcount(mask) <= ans) continue;
            if (check(mask)) ans = __builtin_popcount(mask);
        }

        for (auto nxt : adj[cur.second]) {
            if (erased[nxt]) continue;
            s.erase({deg[nxt], nxt}); deg[nxt]--;
            s.insert({deg[nxt], nxt});
        }
        erased[cur.second] = true;

    }


    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1488 KB Output is correct
3 Correct 8 ms 1876 KB Output is correct
4 Correct 7 ms 1908 KB Output is correct
5 Correct 6 ms 1876 KB Output is correct
6 Correct 6 ms 1876 KB Output is correct
7 Correct 7 ms 1892 KB Output is correct
8 Incorrect 3 ms 1748 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1488 KB Output is correct
3 Correct 8 ms 1876 KB Output is correct
4 Correct 7 ms 1908 KB Output is correct
5 Correct 6 ms 1876 KB Output is correct
6 Correct 6 ms 1876 KB Output is correct
7 Correct 7 ms 1892 KB Output is correct
8 Incorrect 3 ms 1748 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1488 KB Output is correct
3 Correct 8 ms 1876 KB Output is correct
4 Correct 7 ms 1908 KB Output is correct
5 Correct 6 ms 1876 KB Output is correct
6 Correct 6 ms 1876 KB Output is correct
7 Correct 7 ms 1892 KB Output is correct
8 Incorrect 3 ms 1748 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1488 KB Output is correct
3 Correct 8 ms 1876 KB Output is correct
4 Correct 7 ms 1908 KB Output is correct
5 Correct 6 ms 1876 KB Output is correct
6 Correct 6 ms 1876 KB Output is correct
7 Correct 7 ms 1892 KB Output is correct
8 Incorrect 3 ms 1748 KB Output isn't correct
9 Halted 0 ms 0 KB -