답안 #647887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647887 2022-10-04T11:50:29 Z mychecksedad Political Development (BOI17_politicaldevelopment) C++17
77 / 100
3000 ms 383336 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;


int n, k;
vector<int> g[N], path;
vector<bool> vis(N);
vector<bitset<50001>> is;
ll e[N];
void dfs(int v, int p){
    vis[v] = 1;
    path.pb(v);
    for(int u: g[v]){
        if(u != p){
            if(vis[u]){
                if(path[path.size() - 3] == u){
                    cout << 3;
                    exit(0);
                }
            }else{
                dfs(u, v);
            }
        }    
    }
    path.pop_back();
}

int mod(ll a){
    return ((a % MOD) + MOD) % MOD;
}

void solve(){
    cin >> n >> k;
    is.resize(n+1);
    for(int i = 0; i < n; ++i){
        int d; cin >> d;
        for(int j = 0; j < d; ++j){
            int x; cin >> x; g[i].pb(x); is[i][x] = 1;
        }
    }
    if(k <= 2){
        for(int i = 0; i < n; ++i){
            if(g[i].size()){
                cout << 2;
                return;
            }
        }
        cout << 1;
        return;
    }
    if(k <= 3){
        for(int i = 0; i < n; ++i) if(!vis[i]) dfs(i, i);
        for(int i = 0; i < n; ++i){
            if(g[i].size()){
                cout << 2;
                return;
            }
        }
        cout << 1;
        return;
    }

    e[0] = 1;
    for(int i = 1; i < N; ++i) e[i] = (e[i - 1] * 3) % MOD;

    vector<vector<int>> v;
    for(int i = 0; i < n; ++i) v.pb({i});
    for(int j = 2; j <= k; ++j){
        bitset<50001> out, in;
        vector<vector<int>> t;
        map<ll, bool> m;

        for(auto &u: v){
            ll h = 0;
            for(int x: u) in[x] = 1, h += e[x];
            h = mod(h);
            vector<int> extend;
            for(int x: u){
                for(int e: g[x]){
                    if(!out[e] && !in[e]){
                        out[e] = 1;
                        extend.pb(e);
                    }
                }
            }
            for(int x: extend){
                out[x] = 0;
                bool ok = 1;
                for(int p: u){
                    if(!is[p][x]){
                        ok = 0;
                        break;
                    }
                }
                if(ok){
                    h = mod(h + e[x]);
                    if(!m[h]){
                        m[h] = 1;
                        u.pb(x);
                        t.pb(u);
                        u.pop_back();
                    }
                    h = mod(h - e[x]);
                }
            }
            for(int x: u) in[x] = 0;
        }
        if(t.size() == 0){
            cout << j - 1;
            return;
        }
        v = t;
    }
    cout << k;
}   





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
 
}

Compilation message

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:137:16: warning: unused variable 'aa' [-Wunused-variable]
  137 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23892 KB Output is correct
2 Correct 13 ms 23892 KB Output is correct
3 Correct 27 ms 54672 KB Output is correct
4 Correct 26 ms 54692 KB Output is correct
5 Correct 25 ms 54740 KB Output is correct
6 Correct 25 ms 54748 KB Output is correct
7 Correct 25 ms 54732 KB Output is correct
8 Correct 25 ms 54552 KB Output is correct
9 Correct 13 ms 23892 KB Output is correct
10 Correct 25 ms 54484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23892 KB Output is correct
2 Correct 13 ms 23892 KB Output is correct
3 Correct 27 ms 54672 KB Output is correct
4 Correct 26 ms 54692 KB Output is correct
5 Correct 25 ms 54740 KB Output is correct
6 Correct 25 ms 54748 KB Output is correct
7 Correct 25 ms 54732 KB Output is correct
8 Correct 25 ms 54552 KB Output is correct
9 Correct 13 ms 23892 KB Output is correct
10 Correct 25 ms 54484 KB Output is correct
11 Correct 29 ms 54792 KB Output is correct
12 Correct 26 ms 54660 KB Output is correct
13 Correct 12 ms 23940 KB Output is correct
14 Correct 25 ms 54628 KB Output is correct
15 Correct 13 ms 23936 KB Output is correct
16 Correct 24 ms 54684 KB Output is correct
17 Correct 15 ms 23932 KB Output is correct
18 Correct 28 ms 54728 KB Output is correct
19 Correct 24 ms 54472 KB Output is correct
20 Correct 27 ms 54604 KB Output is correct
21 Correct 26 ms 54612 KB Output is correct
22 Correct 27 ms 54560 KB Output is correct
23 Correct 28 ms 54732 KB Output is correct
24 Correct 25 ms 54484 KB Output is correct
25 Correct 27 ms 54672 KB Output is correct
26 Correct 28 ms 54740 KB Output is correct
27 Correct 33 ms 55020 KB Output is correct
28 Correct 32 ms 54732 KB Output is correct
29 Correct 29 ms 54996 KB Output is correct
30 Correct 29 ms 54740 KB Output is correct
31 Correct 30 ms 54872 KB Output is correct
32 Correct 27 ms 54712 KB Output is correct
33 Correct 26 ms 54788 KB Output is correct
34 Correct 29 ms 54912 KB Output is correct
35 Correct 22 ms 39348 KB Output is correct
36 Correct 25 ms 39380 KB Output is correct
37 Correct 24 ms 39400 KB Output is correct
38 Correct 17 ms 31584 KB Output is correct
39 Correct 17 ms 31612 KB Output is correct
40 Correct 27 ms 54740 KB Output is correct
41 Correct 16 ms 31644 KB Output is correct
42 Correct 27 ms 54672 KB Output is correct
43 Correct 27 ms 54700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 62692 KB Output is correct
2 Correct 20 ms 31904 KB Output is correct
3 Correct 21 ms 31828 KB Output is correct
4 Correct 23 ms 31844 KB Output is correct
5 Correct 22 ms 31848 KB Output is correct
6 Correct 19 ms 31828 KB Output is correct
7 Correct 21 ms 31872 KB Output is correct
8 Correct 21 ms 31824 KB Output is correct
9 Correct 25 ms 31836 KB Output is correct
10 Correct 21 ms 31828 KB Output is correct
11 Correct 767 ms 383140 KB Output is correct
12 Correct 20 ms 31828 KB Output is correct
13 Correct 791 ms 383240 KB Output is correct
14 Correct 20 ms 31828 KB Output is correct
15 Correct 778 ms 383336 KB Output is correct
16 Correct 808 ms 383216 KB Output is correct
17 Correct 772 ms 383152 KB Output is correct
18 Correct 776 ms 383264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23892 KB Output is correct
2 Correct 13 ms 23892 KB Output is correct
3 Correct 27 ms 54672 KB Output is correct
4 Correct 26 ms 54692 KB Output is correct
5 Correct 25 ms 54740 KB Output is correct
6 Correct 25 ms 54748 KB Output is correct
7 Correct 25 ms 54732 KB Output is correct
8 Correct 25 ms 54552 KB Output is correct
9 Correct 13 ms 23892 KB Output is correct
10 Correct 25 ms 54484 KB Output is correct
11 Correct 29 ms 54792 KB Output is correct
12 Correct 26 ms 54660 KB Output is correct
13 Correct 12 ms 23940 KB Output is correct
14 Correct 25 ms 54628 KB Output is correct
15 Correct 13 ms 23936 KB Output is correct
16 Correct 24 ms 54684 KB Output is correct
17 Correct 15 ms 23932 KB Output is correct
18 Correct 28 ms 54728 KB Output is correct
19 Correct 24 ms 54472 KB Output is correct
20 Correct 27 ms 54604 KB Output is correct
21 Correct 26 ms 54612 KB Output is correct
22 Correct 27 ms 54560 KB Output is correct
23 Correct 28 ms 54732 KB Output is correct
24 Correct 25 ms 54484 KB Output is correct
25 Correct 27 ms 54672 KB Output is correct
26 Correct 28 ms 54740 KB Output is correct
27 Correct 33 ms 55020 KB Output is correct
28 Correct 32 ms 54732 KB Output is correct
29 Correct 29 ms 54996 KB Output is correct
30 Correct 29 ms 54740 KB Output is correct
31 Correct 30 ms 54872 KB Output is correct
32 Correct 27 ms 54712 KB Output is correct
33 Correct 26 ms 54788 KB Output is correct
34 Correct 29 ms 54912 KB Output is correct
35 Correct 22 ms 39348 KB Output is correct
36 Correct 25 ms 39380 KB Output is correct
37 Correct 24 ms 39400 KB Output is correct
38 Correct 17 ms 31584 KB Output is correct
39 Correct 17 ms 31612 KB Output is correct
40 Correct 27 ms 54740 KB Output is correct
41 Correct 16 ms 31644 KB Output is correct
42 Correct 27 ms 54672 KB Output is correct
43 Correct 27 ms 54700 KB Output is correct
44 Correct 497 ms 79272 KB Output is correct
45 Correct 19 ms 31836 KB Output is correct
46 Correct 48 ms 64516 KB Output is correct
47 Correct 65 ms 66324 KB Output is correct
48 Correct 46 ms 64652 KB Output is correct
49 Correct 67 ms 66564 KB Output is correct
50 Correct 64 ms 66460 KB Output is correct
51 Correct 114 ms 70356 KB Output is correct
52 Correct 27 ms 54684 KB Output is correct
53 Correct 1818 ms 71408 KB Output is correct
54 Correct 132 ms 71364 KB Output is correct
55 Correct 41 ms 63420 KB Output is correct
56 Correct 25 ms 54728 KB Output is correct
57 Correct 34 ms 62664 KB Output is correct
58 Correct 1829 ms 71320 KB Output is correct
59 Correct 67 ms 64932 KB Output is correct
60 Correct 43 ms 63456 KB Output is correct
61 Correct 57 ms 64936 KB Output is correct
62 Correct 58 ms 64932 KB Output is correct
63 Correct 532 ms 79516 KB Output is correct
64 Correct 250 ms 72180 KB Output is correct
65 Correct 46 ms 64400 KB Output is correct
66 Correct 61 ms 64804 KB Output is correct
67 Correct 198 ms 67292 KB Output is correct
68 Correct 255 ms 72184 KB Output is correct
69 Correct 44 ms 64400 KB Output is correct
70 Correct 71 ms 66196 KB Output is correct
71 Correct 197 ms 67228 KB Output is correct
72 Correct 124 ms 67168 KB Output is correct
73 Correct 38 ms 63432 KB Output is correct
74 Correct 73 ms 66132 KB Output is correct
75 Correct 135 ms 67208 KB Output is correct
76 Correct 99 ms 65220 KB Output is correct
77 Correct 81 ms 68244 KB Output is correct
78 Correct 38 ms 63436 KB Output is correct
79 Correct 50 ms 50004 KB Output is correct
80 Correct 102 ms 65340 KB Output is correct
81 Correct 93 ms 68208 KB Output is correct
82 Correct 26 ms 39864 KB Output is correct
83 Correct 49 ms 50000 KB Output is correct
84 Correct 67 ms 67080 KB Output is correct
85 Correct 27 ms 39916 KB Output is correct
86 Correct 74 ms 67112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23892 KB Output is correct
2 Correct 13 ms 23892 KB Output is correct
3 Correct 27 ms 54672 KB Output is correct
4 Correct 26 ms 54692 KB Output is correct
5 Correct 25 ms 54740 KB Output is correct
6 Correct 25 ms 54748 KB Output is correct
7 Correct 25 ms 54732 KB Output is correct
8 Correct 25 ms 54552 KB Output is correct
9 Correct 13 ms 23892 KB Output is correct
10 Correct 25 ms 54484 KB Output is correct
11 Correct 29 ms 54792 KB Output is correct
12 Correct 26 ms 54660 KB Output is correct
13 Correct 12 ms 23940 KB Output is correct
14 Correct 25 ms 54628 KB Output is correct
15 Correct 13 ms 23936 KB Output is correct
16 Correct 24 ms 54684 KB Output is correct
17 Correct 15 ms 23932 KB Output is correct
18 Correct 28 ms 54728 KB Output is correct
19 Correct 24 ms 54472 KB Output is correct
20 Correct 27 ms 54604 KB Output is correct
21 Correct 26 ms 54612 KB Output is correct
22 Correct 27 ms 54560 KB Output is correct
23 Correct 28 ms 54732 KB Output is correct
24 Correct 25 ms 54484 KB Output is correct
25 Correct 27 ms 54672 KB Output is correct
26 Correct 28 ms 54740 KB Output is correct
27 Correct 33 ms 55020 KB Output is correct
28 Correct 32 ms 54732 KB Output is correct
29 Correct 29 ms 54996 KB Output is correct
30 Correct 29 ms 54740 KB Output is correct
31 Correct 30 ms 54872 KB Output is correct
32 Correct 27 ms 54712 KB Output is correct
33 Correct 26 ms 54788 KB Output is correct
34 Correct 29 ms 54912 KB Output is correct
35 Correct 22 ms 39348 KB Output is correct
36 Correct 25 ms 39380 KB Output is correct
37 Correct 24 ms 39400 KB Output is correct
38 Correct 17 ms 31584 KB Output is correct
39 Correct 17 ms 31612 KB Output is correct
40 Correct 27 ms 54740 KB Output is correct
41 Correct 16 ms 31644 KB Output is correct
42 Correct 27 ms 54672 KB Output is correct
43 Correct 27 ms 54700 KB Output is correct
44 Correct 19 ms 31828 KB Output is correct
45 Correct 588 ms 368740 KB Output is correct
46 Execution timed out 3111 ms 355128 KB Time limit exceeded
47 Halted 0 ms 0 KB -