Submission #785767

# Submission time Handle Problem Language Result Execution time Memory
785767 2023-07-17T14:51:29 Z SlavicG Political Development (BOI17_politicaldevelopment) C++17
100 / 100
266 ms 48680 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()
 
const int N = 5e4 + 10;
unordered_set<int> st[N];
vector<int> adj[N];
set<int> aaa[N];
int ans = 1;
 
void solve() {
    int n, k; cin >> n >> k;
    queue<int> q;

    vector<bool> pushed(n, false);
    for(int i = 0; i < n; ++i) {
        int x; cin >> x; 
        if(x >= 1) {
            for(int j = 0; j < x; ++j) {
                int bl; cin >> bl;
                aaa[i].insert(bl);
                st[i].insert(bl);
            }
        } 
        if(x < k) {
            q.push(i);
            pushed[i] = true;
        } 
    }
    while(!q.empty()) {
        int i = q.front();
        q.pop();
        for(auto x: aaa[i]) adj[i].pb(x);
        vector<int> dp(1 << (sz(adj[i])), 0);
        dp[0] = 1;
        for(int mask = 0; mask < (1 << (sz(adj[i]))); ++mask) {
            if(!dp[mask]) continue;
            int cnt = 1;
            for(int f = 0; f < sz(adj[i]); ++f) {
                if(mask >> f & 1) ++cnt;
            }
            ans = max(ans, cnt);
            for(int j = 0; j < sz(adj[i]); ++j) {
                if(mask >> j & 1) continue;
                bool check = true;
                for(int f = 0; f < sz(adj[i]); ++f) {
                    if(mask >> f & 1) {
                        if(st[adj[i][j]].find(adj[i][f]) == st[adj[i][j]].end()) check = false;
                    }
                }
                if(check) dp[mask | (1 << j)] = 1;
            }
        }
        for(auto f: adj[i]) {
            aaa[f].erase(i);
            if(sz(aaa[f]) < k && !pushed[f]) {
                pushed[f] = true;
                q.push(f);
            }
        }
    }
    cout << ans << "\n";
}   
 
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Correct 7 ms 8020 KB Output is correct
4 Correct 7 ms 8020 KB Output is correct
5 Correct 7 ms 8004 KB Output is correct
6 Correct 8 ms 8020 KB Output is correct
7 Correct 7 ms 8004 KB Output is correct
8 Correct 4 ms 6592 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 4 ms 6612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Correct 7 ms 8020 KB Output is correct
4 Correct 7 ms 8020 KB Output is correct
5 Correct 7 ms 8004 KB Output is correct
6 Correct 8 ms 8020 KB Output is correct
7 Correct 7 ms 8004 KB Output is correct
8 Correct 4 ms 6592 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 4 ms 6612 KB Output is correct
11 Correct 7 ms 8020 KB Output is correct
12 Correct 7 ms 8020 KB Output is correct
13 Correct 3 ms 6584 KB Output is correct
14 Correct 8 ms 8020 KB Output is correct
15 Correct 3 ms 6588 KB Output is correct
16 Correct 7 ms 8004 KB Output is correct
17 Correct 4 ms 6484 KB Output is correct
18 Correct 7 ms 8000 KB Output is correct
19 Correct 4 ms 6612 KB Output is correct
20 Correct 5 ms 7636 KB Output is correct
21 Correct 5 ms 7620 KB Output is correct
22 Correct 4 ms 6588 KB Output is correct
23 Correct 7 ms 8276 KB Output is correct
24 Correct 3 ms 6612 KB Output is correct
25 Correct 8 ms 8264 KB Output is correct
26 Correct 10 ms 8276 KB Output is correct
27 Correct 6 ms 8004 KB Output is correct
28 Correct 7 ms 8148 KB Output is correct
29 Correct 7 ms 7980 KB Output is correct
30 Correct 8 ms 8276 KB Output is correct
31 Correct 8 ms 8240 KB Output is correct
32 Correct 8 ms 8276 KB Output is correct
33 Correct 8 ms 8264 KB Output is correct
34 Correct 8 ms 8264 KB Output is correct
35 Correct 5 ms 7424 KB Output is correct
36 Correct 5 ms 7360 KB Output is correct
37 Correct 5 ms 7368 KB Output is correct
38 Correct 5 ms 7124 KB Output is correct
39 Correct 5 ms 7108 KB Output is correct
40 Correct 10 ms 8816 KB Output is correct
41 Correct 5 ms 7124 KB Output is correct
42 Correct 10 ms 8900 KB Output is correct
43 Correct 9 ms 8876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6612 KB Output is correct
2 Correct 3 ms 6588 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6580 KB Output is correct
5 Correct 3 ms 6584 KB Output is correct
6 Correct 3 ms 6584 KB Output is correct
7 Correct 3 ms 6484 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6584 KB Output is correct
10 Correct 3 ms 6484 KB Output is correct
11 Correct 236 ms 47908 KB Output is correct
12 Correct 3 ms 6484 KB Output is correct
13 Correct 255 ms 48004 KB Output is correct
14 Correct 3 ms 6484 KB Output is correct
15 Correct 238 ms 47944 KB Output is correct
16 Correct 266 ms 48000 KB Output is correct
17 Correct 257 ms 47868 KB Output is correct
18 Correct 247 ms 47948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Correct 7 ms 8020 KB Output is correct
4 Correct 7 ms 8020 KB Output is correct
5 Correct 7 ms 8004 KB Output is correct
6 Correct 8 ms 8020 KB Output is correct
7 Correct 7 ms 8004 KB Output is correct
8 Correct 4 ms 6592 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 4 ms 6612 KB Output is correct
11 Correct 7 ms 8020 KB Output is correct
12 Correct 7 ms 8020 KB Output is correct
13 Correct 3 ms 6584 KB Output is correct
14 Correct 8 ms 8020 KB Output is correct
15 Correct 3 ms 6588 KB Output is correct
16 Correct 7 ms 8004 KB Output is correct
17 Correct 4 ms 6484 KB Output is correct
18 Correct 7 ms 8000 KB Output is correct
19 Correct 4 ms 6612 KB Output is correct
20 Correct 5 ms 7636 KB Output is correct
21 Correct 5 ms 7620 KB Output is correct
22 Correct 4 ms 6588 KB Output is correct
23 Correct 7 ms 8276 KB Output is correct
24 Correct 3 ms 6612 KB Output is correct
25 Correct 8 ms 8264 KB Output is correct
26 Correct 10 ms 8276 KB Output is correct
27 Correct 6 ms 8004 KB Output is correct
28 Correct 7 ms 8148 KB Output is correct
29 Correct 7 ms 7980 KB Output is correct
30 Correct 8 ms 8276 KB Output is correct
31 Correct 8 ms 8240 KB Output is correct
32 Correct 8 ms 8276 KB Output is correct
33 Correct 8 ms 8264 KB Output is correct
34 Correct 8 ms 8264 KB Output is correct
35 Correct 5 ms 7424 KB Output is correct
36 Correct 5 ms 7360 KB Output is correct
37 Correct 5 ms 7368 KB Output is correct
38 Correct 5 ms 7124 KB Output is correct
39 Correct 5 ms 7108 KB Output is correct
40 Correct 10 ms 8816 KB Output is correct
41 Correct 5 ms 7124 KB Output is correct
42 Correct 10 ms 8900 KB Output is correct
43 Correct 9 ms 8876 KB Output is correct
44 Correct 62 ms 10464 KB Output is correct
45 Correct 3 ms 6484 KB Output is correct
46 Correct 10 ms 8896 KB Output is correct
47 Correct 17 ms 10564 KB Output is correct
48 Correct 10 ms 8896 KB Output is correct
49 Correct 18 ms 10532 KB Output is correct
50 Correct 18 ms 10496 KB Output is correct
51 Correct 38 ms 14152 KB Output is correct
52 Correct 7 ms 8020 KB Output is correct
53 Correct 35 ms 15304 KB Output is correct
54 Correct 49 ms 15436 KB Output is correct
55 Correct 7 ms 8020 KB Output is correct
56 Correct 8 ms 7964 KB Output is correct
57 Correct 3 ms 6588 KB Output is correct
58 Correct 35 ms 15296 KB Output is correct
59 Correct 10 ms 8904 KB Output is correct
60 Correct 8 ms 7996 KB Output is correct
61 Correct 10 ms 8780 KB Output is correct
62 Correct 11 ms 8904 KB Output is correct
63 Correct 61 ms 10468 KB Output is correct
64 Correct 32 ms 10068 KB Output is correct
65 Correct 9 ms 8708 KB Output is correct
66 Correct 10 ms 8788 KB Output is correct
67 Correct 39 ms 11220 KB Output is correct
68 Correct 31 ms 10064 KB Output is correct
69 Correct 9 ms 8640 KB Output is correct
70 Correct 18 ms 10172 KB Output is correct
71 Correct 38 ms 11224 KB Output is correct
72 Correct 32 ms 11092 KB Output is correct
73 Correct 8 ms 8064 KB Output is correct
74 Correct 18 ms 10192 KB Output is correct
75 Correct 30 ms 11092 KB Output is correct
76 Correct 12 ms 9428 KB Output is correct
77 Correct 26 ms 11980 KB Output is correct
78 Correct 7 ms 7944 KB Output is correct
79 Correct 15 ms 9328 KB Output is correct
80 Correct 12 ms 9396 KB Output is correct
81 Correct 26 ms 12084 KB Output is correct
82 Correct 5 ms 7108 KB Output is correct
83 Correct 15 ms 9300 KB Output is correct
84 Correct 20 ms 10808 KB Output is correct
85 Correct 5 ms 7060 KB Output is correct
86 Correct 19 ms 10836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Correct 7 ms 8020 KB Output is correct
4 Correct 7 ms 8020 KB Output is correct
5 Correct 7 ms 8004 KB Output is correct
6 Correct 8 ms 8020 KB Output is correct
7 Correct 7 ms 8004 KB Output is correct
8 Correct 4 ms 6592 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 4 ms 6612 KB Output is correct
11 Correct 7 ms 8020 KB Output is correct
12 Correct 7 ms 8020 KB Output is correct
13 Correct 3 ms 6584 KB Output is correct
14 Correct 8 ms 8020 KB Output is correct
15 Correct 3 ms 6588 KB Output is correct
16 Correct 7 ms 8004 KB Output is correct
17 Correct 4 ms 6484 KB Output is correct
18 Correct 7 ms 8000 KB Output is correct
19 Correct 4 ms 6612 KB Output is correct
20 Correct 5 ms 7636 KB Output is correct
21 Correct 5 ms 7620 KB Output is correct
22 Correct 4 ms 6588 KB Output is correct
23 Correct 7 ms 8276 KB Output is correct
24 Correct 3 ms 6612 KB Output is correct
25 Correct 8 ms 8264 KB Output is correct
26 Correct 10 ms 8276 KB Output is correct
27 Correct 6 ms 8004 KB Output is correct
28 Correct 7 ms 8148 KB Output is correct
29 Correct 7 ms 7980 KB Output is correct
30 Correct 8 ms 8276 KB Output is correct
31 Correct 8 ms 8240 KB Output is correct
32 Correct 8 ms 8276 KB Output is correct
33 Correct 8 ms 8264 KB Output is correct
34 Correct 8 ms 8264 KB Output is correct
35 Correct 5 ms 7424 KB Output is correct
36 Correct 5 ms 7360 KB Output is correct
37 Correct 5 ms 7368 KB Output is correct
38 Correct 5 ms 7124 KB Output is correct
39 Correct 5 ms 7108 KB Output is correct
40 Correct 10 ms 8816 KB Output is correct
41 Correct 5 ms 7124 KB Output is correct
42 Correct 10 ms 8900 KB Output is correct
43 Correct 9 ms 8876 KB Output is correct
44 Correct 3 ms 6484 KB Output is correct
45 Correct 180 ms 37796 KB Output is correct
46 Correct 79 ms 25332 KB Output is correct
47 Correct 176 ms 37708 KB Output is correct
48 Correct 170 ms 37820 KB Output is correct
49 Correct 55 ms 21468 KB Output is correct
50 Correct 174 ms 48680 KB Output is correct
51 Correct 173 ms 37568 KB Output is correct
52 Correct 49 ms 21188 KB Output is correct
53 Correct 51 ms 21488 KB Output is correct
54 Correct 6 ms 6836 KB Output is correct
55 Correct 170 ms 48576 KB Output is correct
56 Correct 31 ms 16560 KB Output is correct
57 Correct 48 ms 21208 KB Output is correct
58 Correct 70 ms 25064 KB Output is correct
59 Correct 31 ms 16528 KB Output is correct
60 Correct 31 ms 16464 KB Output is correct
61 Correct 69 ms 25036 KB Output is correct
62 Correct 47 ms 20796 KB Output is correct
63 Correct 89 ms 26996 KB Output is correct
64 Correct 31 ms 16468 KB Output is correct
65 Correct 126 ms 31176 KB Output is correct
66 Correct 50 ms 20812 KB Output is correct
67 Correct 107 ms 27160 KB Output is correct
68 Correct 121 ms 30176 KB Output is correct
69 Correct 132 ms 31176 KB Output is correct
70 Correct 50 ms 20812 KB Output is correct
71 Correct 115 ms 30176 KB Output is correct
72 Correct 86 ms 26704 KB Output is correct
73 Correct 142 ms 33952 KB Output is correct
74 Correct 50 ms 20812 KB Output is correct
75 Correct 42 ms 17644 KB Output is correct
76 Correct 85 ms 26632 KB Output is correct
77 Correct 143 ms 34004 KB Output is correct
78 Correct 54 ms 20368 KB Output is correct
79 Correct 40 ms 17572 KB Output is correct
80 Correct 20 ms 12360 KB Output is correct
81 Correct 55 ms 20300 KB Output is correct
82 Correct 93 ms 29056 KB Output is correct
83 Correct 20 ms 12360 KB Output is correct
84 Correct 98 ms 29072 KB Output is correct