Submission #480716

# Submission time Handle Problem Language Result Execution time Memory
480716 2021-10-18T00:46:09 Z hidden1 Political Development (BOI17_politicaldevelopment) C++14
100 / 100
504 ms 31228 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#ifndef LOCAL
#define cerr if(false) cerr
#endif

#define forn(N)    for(int i =   0; i < (N); i ++)
#define forab(A, B) for(int i = (A); i < (B); i ++)

const int MAX_N = 1e5 + 10;
set<int> g[MAX_N];
int n, k;

const int MAX_K = 10;
bool adj[MAX_K][1 << MAX_K], can[1 << MAX_K];
int pw[MAX_N];

int solve() {
    multiset<pair<int, int> > st;
    forn(n) {
        st.insert({g[i].size(), i});
    }

    auto rmEdge = [&st](int a, int b) {
        st.erase({g[a].size(), a});
        st.erase({g[b].size(), b});
        g[a].erase(b);
        g[b].erase(a);
        if(g[a].size() != 0) {
            st.insert({g[a].size(), a});
        }
        if(g[b].size() != 0) {
            st.insert({g[b].size(), b});
        }
    };

    auto getClique = [&st](int x) {
        int sz = g[x].size();
        vector<int> vert = {};
        cerr << "from x " << x << ": ";
        for(auto it : g[x]) {
            vert.push_back(it);
            cerr << it << " ";
        }
        cerr << endl;


        forn(sz) {
            fill(adj[i], adj[i] + (1 << sz), false);
            adj[i][0] = true;
            for(int mask = 1; mask < (1 << sz); mask ++) {
                adj[i][mask] = adj[i][mask & (mask - 1)] & (g[vert[i]].find(vert[pw[mask - (mask & (mask - 1))]]) != g[vert[i]].end());
            }
        }
        int ret = 0;

        fill(can, can + (1 << sz), false);
        can[0] = true;

        forn(1 << sz) {
            can[i] = can[i & (i - 1)] & adj[pw[i - (i & (i - 1))]][i & (i - 1)];
            if(can[i]) {
                chkmax(ret, __builtin_popcount(i));
            }
        }
        return ret + 1;
    };

    int ret = 1;

    while(!st.empty()) {
        auto curr = st.begin(); st.erase(curr);
        auto vert = (*curr).second;

        cerr << "Trying vert " << vert << endl;
        chkmax(ret, getClique(vert));
        cerr << "Remove vert " << endl;

        vector<int> toRem = {};
        for(auto it : g[vert]) {toRem.push_back(it);}

        for(auto it : toRem) {
            rmEdge(vert, it);
        }
    }
    return ret;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    for(int i = 0, j = 1; i < MAX_K; i ++, j *= 2) {
        pw[j] = i;
    }

    cin >> n >> k;
    forn(n) {
        int d;
        cin >> d;
        while(d --) {
            int b;
            cin >> b;
            g[i].insert(b);
        }
    }

    cout << solve() << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 9 ms 5792 KB Output is correct
4 Correct 8 ms 5708 KB Output is correct
5 Correct 7 ms 5708 KB Output is correct
6 Correct 9 ms 5784 KB Output is correct
7 Correct 8 ms 5708 KB Output is correct
8 Correct 3 ms 5196 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 9 ms 5792 KB Output is correct
4 Correct 8 ms 5708 KB Output is correct
5 Correct 7 ms 5708 KB Output is correct
6 Correct 9 ms 5784 KB Output is correct
7 Correct 8 ms 5708 KB Output is correct
8 Correct 3 ms 5196 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5196 KB Output is correct
11 Correct 9 ms 5672 KB Output is correct
12 Correct 10 ms 5668 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 8 ms 5708 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 9 ms 5708 KB Output is correct
17 Correct 3 ms 4972 KB Output is correct
18 Correct 8 ms 5788 KB Output is correct
19 Correct 4 ms 5196 KB Output is correct
20 Correct 5 ms 5452 KB Output is correct
21 Correct 5 ms 5452 KB Output is correct
22 Correct 4 ms 5196 KB Output is correct
23 Correct 12 ms 5796 KB Output is correct
24 Correct 4 ms 5196 KB Output is correct
25 Correct 10 ms 5924 KB Output is correct
26 Correct 9 ms 5824 KB Output is correct
27 Correct 8 ms 5708 KB Output is correct
28 Correct 10 ms 5836 KB Output is correct
29 Correct 8 ms 5708 KB Output is correct
30 Correct 11 ms 5960 KB Output is correct
31 Correct 10 ms 5836 KB Output is correct
32 Correct 10 ms 5836 KB Output is correct
33 Correct 10 ms 5836 KB Output is correct
34 Correct 9 ms 5836 KB Output is correct
35 Correct 6 ms 5452 KB Output is correct
36 Correct 7 ms 5452 KB Output is correct
37 Correct 6 ms 5452 KB Output is correct
38 Correct 6 ms 5324 KB Output is correct
39 Correct 5 ms 5284 KB Output is correct
40 Correct 15 ms 6300 KB Output is correct
41 Correct 6 ms 5280 KB Output is correct
42 Correct 14 ms 6308 KB Output is correct
43 Correct 14 ms 6220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5196 KB Output is correct
2 Correct 3 ms 5016 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 5016 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 493 ms 31228 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 493 ms 31128 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 483 ms 31072 KB Output is correct
16 Correct 491 ms 31044 KB Output is correct
17 Correct 504 ms 31132 KB Output is correct
18 Correct 490 ms 31212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 9 ms 5792 KB Output is correct
4 Correct 8 ms 5708 KB Output is correct
5 Correct 7 ms 5708 KB Output is correct
6 Correct 9 ms 5784 KB Output is correct
7 Correct 8 ms 5708 KB Output is correct
8 Correct 3 ms 5196 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5196 KB Output is correct
11 Correct 9 ms 5672 KB Output is correct
12 Correct 10 ms 5668 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 8 ms 5708 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 9 ms 5708 KB Output is correct
17 Correct 3 ms 4972 KB Output is correct
18 Correct 8 ms 5788 KB Output is correct
19 Correct 4 ms 5196 KB Output is correct
20 Correct 5 ms 5452 KB Output is correct
21 Correct 5 ms 5452 KB Output is correct
22 Correct 4 ms 5196 KB Output is correct
23 Correct 12 ms 5796 KB Output is correct
24 Correct 4 ms 5196 KB Output is correct
25 Correct 10 ms 5924 KB Output is correct
26 Correct 9 ms 5824 KB Output is correct
27 Correct 8 ms 5708 KB Output is correct
28 Correct 10 ms 5836 KB Output is correct
29 Correct 8 ms 5708 KB Output is correct
30 Correct 11 ms 5960 KB Output is correct
31 Correct 10 ms 5836 KB Output is correct
32 Correct 10 ms 5836 KB Output is correct
33 Correct 10 ms 5836 KB Output is correct
34 Correct 9 ms 5836 KB Output is correct
35 Correct 6 ms 5452 KB Output is correct
36 Correct 7 ms 5452 KB Output is correct
37 Correct 6 ms 5452 KB Output is correct
38 Correct 6 ms 5324 KB Output is correct
39 Correct 5 ms 5284 KB Output is correct
40 Correct 15 ms 6300 KB Output is correct
41 Correct 6 ms 5280 KB Output is correct
42 Correct 14 ms 6308 KB Output is correct
43 Correct 14 ms 6220 KB Output is correct
44 Correct 45 ms 7320 KB Output is correct
45 Correct 3 ms 4940 KB Output is correct
46 Correct 15 ms 6184 KB Output is correct
47 Correct 31 ms 7204 KB Output is correct
48 Correct 14 ms 6184 KB Output is correct
49 Correct 40 ms 7364 KB Output is correct
50 Correct 34 ms 7244 KB Output is correct
51 Correct 158 ms 9376 KB Output is correct
52 Correct 8 ms 5708 KB Output is correct
53 Correct 298 ms 9892 KB Output is correct
54 Correct 273 ms 9924 KB Output is correct
55 Correct 9 ms 5708 KB Output is correct
56 Correct 8 ms 5788 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 313 ms 9892 KB Output is correct
59 Correct 12 ms 6220 KB Output is correct
60 Correct 8 ms 5668 KB Output is correct
61 Correct 13 ms 6220 KB Output is correct
62 Correct 13 ms 6308 KB Output is correct
63 Correct 37 ms 7336 KB Output is correct
64 Correct 29 ms 7084 KB Output is correct
65 Correct 13 ms 6092 KB Output is correct
66 Correct 13 ms 6308 KB Output is correct
67 Correct 46 ms 7756 KB Output is correct
68 Correct 28 ms 6988 KB Output is correct
69 Correct 13 ms 6092 KB Output is correct
70 Correct 27 ms 7076 KB Output is correct
71 Correct 45 ms 7712 KB Output is correct
72 Correct 42 ms 7628 KB Output is correct
73 Correct 8 ms 5676 KB Output is correct
74 Correct 28 ms 7152 KB Output is correct
75 Correct 40 ms 7628 KB Output is correct
76 Correct 21 ms 6648 KB Output is correct
77 Correct 69 ms 8128 KB Output is correct
78 Correct 9 ms 5668 KB Output is correct
79 Correct 36 ms 6564 KB Output is correct
80 Correct 20 ms 6636 KB Output is correct
81 Correct 67 ms 8140 KB Output is correct
82 Correct 5 ms 5324 KB Output is correct
83 Correct 36 ms 6604 KB Output is correct
84 Correct 47 ms 7576 KB Output is correct
85 Correct 6 ms 5452 KB Output is correct
86 Correct 45 ms 7636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 9 ms 5792 KB Output is correct
4 Correct 8 ms 5708 KB Output is correct
5 Correct 7 ms 5708 KB Output is correct
6 Correct 9 ms 5784 KB Output is correct
7 Correct 8 ms 5708 KB Output is correct
8 Correct 3 ms 5196 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 5196 KB Output is correct
11 Correct 9 ms 5672 KB Output is correct
12 Correct 10 ms 5668 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 8 ms 5708 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 9 ms 5708 KB Output is correct
17 Correct 3 ms 4972 KB Output is correct
18 Correct 8 ms 5788 KB Output is correct
19 Correct 4 ms 5196 KB Output is correct
20 Correct 5 ms 5452 KB Output is correct
21 Correct 5 ms 5452 KB Output is correct
22 Correct 4 ms 5196 KB Output is correct
23 Correct 12 ms 5796 KB Output is correct
24 Correct 4 ms 5196 KB Output is correct
25 Correct 10 ms 5924 KB Output is correct
26 Correct 9 ms 5824 KB Output is correct
27 Correct 8 ms 5708 KB Output is correct
28 Correct 10 ms 5836 KB Output is correct
29 Correct 8 ms 5708 KB Output is correct
30 Correct 11 ms 5960 KB Output is correct
31 Correct 10 ms 5836 KB Output is correct
32 Correct 10 ms 5836 KB Output is correct
33 Correct 10 ms 5836 KB Output is correct
34 Correct 9 ms 5836 KB Output is correct
35 Correct 6 ms 5452 KB Output is correct
36 Correct 7 ms 5452 KB Output is correct
37 Correct 6 ms 5452 KB Output is correct
38 Correct 6 ms 5324 KB Output is correct
39 Correct 5 ms 5284 KB Output is correct
40 Correct 15 ms 6300 KB Output is correct
41 Correct 6 ms 5280 KB Output is correct
42 Correct 14 ms 6308 KB Output is correct
43 Correct 14 ms 6220 KB Output is correct
44 Correct 3 ms 4940 KB Output is correct
45 Correct 257 ms 23184 KB Output is correct
46 Correct 112 ms 15300 KB Output is correct
47 Correct 267 ms 23312 KB Output is correct
48 Correct 258 ms 23236 KB Output is correct
49 Correct 68 ms 12612 KB Output is correct
50 Correct 300 ms 28524 KB Output is correct
51 Correct 260 ms 23108 KB Output is correct
52 Correct 71 ms 12704 KB Output is correct
53 Correct 87 ms 12628 KB Output is correct
54 Correct 19 ms 7460 KB Output is correct
55 Correct 331 ms 28524 KB Output is correct
56 Correct 35 ms 10052 KB Output is correct
57 Correct 72 ms 12600 KB Output is correct
58 Correct 88 ms 15300 KB Output is correct
59 Correct 35 ms 10080 KB Output is correct
60 Correct 35 ms 10088 KB Output is correct
61 Correct 95 ms 15356 KB Output is correct
62 Correct 73 ms 12696 KB Output is correct
63 Correct 141 ms 16580 KB Output is correct
64 Correct 41 ms 10060 KB Output is correct
65 Correct 180 ms 19340 KB Output is correct
66 Correct 64 ms 12708 KB Output is correct
67 Correct 140 ms 16544 KB Output is correct
68 Correct 167 ms 18612 KB Output is correct
69 Correct 188 ms 19244 KB Output is correct
70 Correct 77 ms 12612 KB Output is correct
71 Correct 174 ms 18720 KB Output is correct
72 Correct 137 ms 16196 KB Output is correct
73 Correct 205 ms 20932 KB Output is correct
74 Correct 72 ms 12716 KB Output is correct
75 Correct 71 ms 11340 KB Output is correct
76 Correct 138 ms 16164 KB Output is correct
77 Correct 204 ms 20976 KB Output is correct
78 Correct 100 ms 12964 KB Output is correct
79 Correct 72 ms 11312 KB Output is correct
80 Correct 32 ms 8096 KB Output is correct
81 Correct 94 ms 12940 KB Output is correct
82 Correct 150 ms 17976 KB Output is correct
83 Correct 33 ms 8168 KB Output is correct
84 Correct 161 ms 17876 KB Output is correct