Submission #682716

# Submission time Handle Problem Language Result Execution time Memory
682716 2023-01-16T20:34:03 Z Lobo Political Development (BOI17_politicaldevelopment) C++17
100 / 100
369 ms 36704 KB
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 5e4+10;

int n, k, gr[maxn];
vector<int> g[maxn];
set<int> stg[maxn];

vector<int> vrts,adds;
int bck(int i) {
    if(i == vrts.size()) return adds.size();
    int ans = bck(i+1);
    int u = vrts[i];
    bool ok = true;
    for(auto v : adds) if(stg[u].count(v) == 0) ok = false;

    if(ok) {
        adds.pb(u);
        ans = max(ans, bck(i+1));
        adds.pop_back();
    }
    return ans;
}

void solve() {
    cin >> n >> k;
    int ans = 1;
    for(int i = 0; i < n; i++) {
        int d; cin >> d; 
        gr[i] = d;
        while(d--) {
            int x; cin >> x;
            stg[i].insert(x);
            g[i].pb(x);
        }
    }

    set<pair<int,int>> st;
    for(int i = 0; i < n; i++) {
        st.insert(mp(gr[i],i));
    }

    while(st.size()) {
        int u = st.begin()->sc;
        st.erase(st.begin());
        if(gr[u] >= k) {
            ans = k;
            break;
        }
        vrts.clear();
        adds.pb(u);
        for(auto v : stg[u]) vrts.pb(v);
        ans = max(ans, bck(0));
        adds.pop_back();

        // bool ok = true;
        // for(auto v1 : stg[u]) {
        //     for(auto v2 : stg[u]) {
        //         if(v1 != v2 && stg[v1].count(v2) == 0) ok = false;
        //     }
        // }
        // if(ok) ans = max(ans, gr[u]+1);

        
        for(auto v : stg[u]) {
            stg[v].erase(u);
            st.erase(mp(gr[v],v));
            --gr[v];
            st.insert(mp(gr[v],v));
        }
    }
    
    cout << ans << endl;
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}

Compilation message

politicaldevelopment.cpp: In function 'long long int bck(long long int)':
politicaldevelopment.cpp:21:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     if(i == vrts.size()) return adds.size();
      |        ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 7 ms 4888 KB Output is correct
4 Correct 9 ms 4820 KB Output is correct
5 Correct 8 ms 4880 KB Output is correct
6 Correct 7 ms 4948 KB Output is correct
7 Correct 9 ms 4948 KB Output is correct
8 Correct 3 ms 4112 KB Output is correct
9 Correct 3 ms 3796 KB Output is correct
10 Correct 3 ms 4116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 7 ms 4888 KB Output is correct
4 Correct 9 ms 4820 KB Output is correct
5 Correct 8 ms 4880 KB Output is correct
6 Correct 7 ms 4948 KB Output is correct
7 Correct 9 ms 4948 KB Output is correct
8 Correct 3 ms 4112 KB Output is correct
9 Correct 3 ms 3796 KB Output is correct
10 Correct 3 ms 4116 KB Output is correct
11 Correct 7 ms 4888 KB Output is correct
12 Correct 8 ms 5000 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 7 ms 4820 KB Output is correct
15 Correct 2 ms 3796 KB Output is correct
16 Correct 7 ms 4948 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 6 ms 4948 KB Output is correct
19 Correct 4 ms 4180 KB Output is correct
20 Correct 5 ms 4628 KB Output is correct
21 Correct 5 ms 4564 KB Output is correct
22 Correct 4 ms 4180 KB Output is correct
23 Correct 9 ms 5044 KB Output is correct
24 Correct 4 ms 4180 KB Output is correct
25 Correct 10 ms 5012 KB Output is correct
26 Correct 7 ms 4948 KB Output is correct
27 Correct 7 ms 4872 KB Output is correct
28 Correct 7 ms 4868 KB Output is correct
29 Correct 6 ms 4884 KB Output is correct
30 Correct 9 ms 5104 KB Output is correct
31 Correct 8 ms 5096 KB Output is correct
32 Correct 10 ms 5076 KB Output is correct
33 Correct 8 ms 5076 KB Output is correct
34 Correct 8 ms 5008 KB Output is correct
35 Correct 5 ms 4436 KB Output is correct
36 Correct 5 ms 4436 KB Output is correct
37 Correct 5 ms 4436 KB Output is correct
38 Correct 5 ms 4180 KB Output is correct
39 Correct 5 ms 4236 KB Output is correct
40 Correct 15 ms 5460 KB Output is correct
41 Correct 4 ms 4240 KB Output is correct
42 Correct 14 ms 5464 KB Output is correct
43 Correct 13 ms 5516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 2 ms 3752 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 369 ms 36424 KB Output is correct
12 Correct 4 ms 3796 KB Output is correct
13 Correct 320 ms 36448 KB Output is correct
14 Correct 2 ms 3796 KB Output is correct
15 Correct 313 ms 36664 KB Output is correct
16 Correct 303 ms 36312 KB Output is correct
17 Correct 351 ms 36432 KB Output is correct
18 Correct 317 ms 36704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 7 ms 4888 KB Output is correct
4 Correct 9 ms 4820 KB Output is correct
5 Correct 8 ms 4880 KB Output is correct
6 Correct 7 ms 4948 KB Output is correct
7 Correct 9 ms 4948 KB Output is correct
8 Correct 3 ms 4112 KB Output is correct
9 Correct 3 ms 3796 KB Output is correct
10 Correct 3 ms 4116 KB Output is correct
11 Correct 7 ms 4888 KB Output is correct
12 Correct 8 ms 5000 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 7 ms 4820 KB Output is correct
15 Correct 2 ms 3796 KB Output is correct
16 Correct 7 ms 4948 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 6 ms 4948 KB Output is correct
19 Correct 4 ms 4180 KB Output is correct
20 Correct 5 ms 4628 KB Output is correct
21 Correct 5 ms 4564 KB Output is correct
22 Correct 4 ms 4180 KB Output is correct
23 Correct 9 ms 5044 KB Output is correct
24 Correct 4 ms 4180 KB Output is correct
25 Correct 10 ms 5012 KB Output is correct
26 Correct 7 ms 4948 KB Output is correct
27 Correct 7 ms 4872 KB Output is correct
28 Correct 7 ms 4868 KB Output is correct
29 Correct 6 ms 4884 KB Output is correct
30 Correct 9 ms 5104 KB Output is correct
31 Correct 8 ms 5096 KB Output is correct
32 Correct 10 ms 5076 KB Output is correct
33 Correct 8 ms 5076 KB Output is correct
34 Correct 8 ms 5008 KB Output is correct
35 Correct 5 ms 4436 KB Output is correct
36 Correct 5 ms 4436 KB Output is correct
37 Correct 5 ms 4436 KB Output is correct
38 Correct 5 ms 4180 KB Output is correct
39 Correct 5 ms 4236 KB Output is correct
40 Correct 15 ms 5460 KB Output is correct
41 Correct 4 ms 4240 KB Output is correct
42 Correct 14 ms 5464 KB Output is correct
43 Correct 13 ms 5516 KB Output is correct
44 Correct 27 ms 6616 KB Output is correct
45 Correct 2 ms 3796 KB Output is correct
46 Correct 12 ms 5428 KB Output is correct
47 Correct 23 ms 6672 KB Output is correct
48 Correct 14 ms 5460 KB Output is correct
49 Correct 22 ms 6696 KB Output is correct
50 Correct 23 ms 6652 KB Output is correct
51 Correct 50 ms 8904 KB Output is correct
52 Correct 7 ms 4820 KB Output is correct
53 Correct 43 ms 9724 KB Output is correct
54 Correct 68 ms 9640 KB Output is correct
55 Correct 9 ms 4856 KB Output is correct
56 Correct 8 ms 4820 KB Output is correct
57 Correct 3 ms 4180 KB Output is correct
58 Correct 40 ms 9556 KB Output is correct
59 Correct 10 ms 5460 KB Output is correct
60 Correct 7 ms 4884 KB Output is correct
61 Correct 10 ms 5480 KB Output is correct
62 Correct 10 ms 5456 KB Output is correct
63 Correct 29 ms 6544 KB Output is correct
64 Correct 21 ms 6356 KB Output is correct
65 Correct 12 ms 5368 KB Output is correct
66 Correct 13 ms 5356 KB Output is correct
67 Correct 31 ms 7192 KB Output is correct
68 Correct 21 ms 6360 KB Output is correct
69 Correct 12 ms 5380 KB Output is correct
70 Correct 20 ms 6356 KB Output is correct
71 Correct 29 ms 7136 KB Output is correct
72 Correct 28 ms 7040 KB Output is correct
73 Correct 7 ms 4880 KB Output is correct
74 Correct 21 ms 6480 KB Output is correct
75 Correct 29 ms 7128 KB Output is correct
76 Correct 16 ms 5844 KB Output is correct
77 Correct 32 ms 7820 KB Output is correct
78 Correct 7 ms 4892 KB Output is correct
79 Correct 17 ms 5844 KB Output is correct
80 Correct 14 ms 5932 KB Output is correct
81 Correct 33 ms 7812 KB Output is correct
82 Correct 4 ms 4180 KB Output is correct
83 Correct 16 ms 5864 KB Output is correct
84 Correct 24 ms 7104 KB Output is correct
85 Correct 5 ms 4180 KB Output is correct
86 Correct 23 ms 7196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 7 ms 4888 KB Output is correct
4 Correct 9 ms 4820 KB Output is correct
5 Correct 8 ms 4880 KB Output is correct
6 Correct 7 ms 4948 KB Output is correct
7 Correct 9 ms 4948 KB Output is correct
8 Correct 3 ms 4112 KB Output is correct
9 Correct 3 ms 3796 KB Output is correct
10 Correct 3 ms 4116 KB Output is correct
11 Correct 7 ms 4888 KB Output is correct
12 Correct 8 ms 5000 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 7 ms 4820 KB Output is correct
15 Correct 2 ms 3796 KB Output is correct
16 Correct 7 ms 4948 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 6 ms 4948 KB Output is correct
19 Correct 4 ms 4180 KB Output is correct
20 Correct 5 ms 4628 KB Output is correct
21 Correct 5 ms 4564 KB Output is correct
22 Correct 4 ms 4180 KB Output is correct
23 Correct 9 ms 5044 KB Output is correct
24 Correct 4 ms 4180 KB Output is correct
25 Correct 10 ms 5012 KB Output is correct
26 Correct 7 ms 4948 KB Output is correct
27 Correct 7 ms 4872 KB Output is correct
28 Correct 7 ms 4868 KB Output is correct
29 Correct 6 ms 4884 KB Output is correct
30 Correct 9 ms 5104 KB Output is correct
31 Correct 8 ms 5096 KB Output is correct
32 Correct 10 ms 5076 KB Output is correct
33 Correct 8 ms 5076 KB Output is correct
34 Correct 8 ms 5008 KB Output is correct
35 Correct 5 ms 4436 KB Output is correct
36 Correct 5 ms 4436 KB Output is correct
37 Correct 5 ms 4436 KB Output is correct
38 Correct 5 ms 4180 KB Output is correct
39 Correct 5 ms 4236 KB Output is correct
40 Correct 15 ms 5460 KB Output is correct
41 Correct 4 ms 4240 KB Output is correct
42 Correct 14 ms 5464 KB Output is correct
43 Correct 13 ms 5516 KB Output is correct
44 Correct 3 ms 3796 KB Output is correct
45 Correct 222 ms 26020 KB Output is correct
46 Correct 86 ms 16984 KB Output is correct
47 Correct 228 ms 26184 KB Output is correct
48 Correct 201 ms 26108 KB Output is correct
49 Correct 61 ms 14568 KB Output is correct
50 Correct 211 ms 31244 KB Output is correct
51 Correct 226 ms 26048 KB Output is correct
52 Correct 55 ms 14392 KB Output is correct
53 Correct 62 ms 14304 KB Output is correct
54 Correct 14 ms 7432 KB Output is correct
55 Correct 205 ms 31136 KB Output is correct
56 Correct 35 ms 11384 KB Output is correct
57 Correct 53 ms 14624 KB Output is correct
58 Correct 75 ms 17252 KB Output is correct
59 Correct 38 ms 11388 KB Output is correct
60 Correct 50 ms 11384 KB Output is correct
61 Correct 77 ms 17404 KB Output is correct
62 Correct 53 ms 13924 KB Output is correct
63 Correct 117 ms 18732 KB Output is correct
64 Correct 38 ms 11536 KB Output is correct
65 Correct 167 ms 21676 KB Output is correct
66 Correct 56 ms 14028 KB Output is correct
67 Correct 113 ms 18508 KB Output is correct
68 Correct 155 ms 20916 KB Output is correct
69 Correct 185 ms 21688 KB Output is correct
70 Correct 62 ms 14100 KB Output is correct
71 Correct 140 ms 20944 KB Output is correct
72 Correct 105 ms 18360 KB Output is correct
73 Correct 165 ms 23488 KB Output is correct
74 Correct 62 ms 13980 KB Output is correct
75 Correct 59 ms 11832 KB Output is correct
76 Correct 117 ms 18296 KB Output is correct
77 Correct 185 ms 23496 KB Output is correct
78 Correct 74 ms 13824 KB Output is correct
79 Correct 72 ms 11816 KB Output is correct
80 Correct 25 ms 7692 KB Output is correct
81 Correct 73 ms 13768 KB Output is correct
82 Correct 120 ms 19788 KB Output is correct
83 Correct 24 ms 7884 KB Output is correct
84 Correct 118 ms 19860 KB Output is correct