Submission #764668

# Submission time Handle Problem Language Result Execution time Memory
764668 2023-06-23T20:42:43 Z adrilen Political Development (BOI17_politicaldevelopment) C++17
4 / 100
3000 ms 31948 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using arr = array<int, 2>;

constexpr int maxn = 5e4;

bool visited[maxn] = { 0 };

set<int> adj[maxn];
int k;
int output = 1;


void dfs(int pos)
{
    // cout << pos << endl;
    visited[pos] = true;
    vector <bitset<10>> v(adj[pos].size());
    int ii = 0; // Counts which place it is in the order of adj[pos]
    int iii;
    for (int i : adj[pos])
    {
        auto it = adj[pos].begin();
        auto ft = adj[i].begin();


        iii = 0;

        v[ii][ii] = true;

        while (it != adj[pos].end() && ft != adj[i].end())
        {
            if (*it < *ft)
            {
                it++;
                iii++;
                continue;
            }

            if (*ft < *it)
            {
                ft++;
                continue;
            }

            v[ii][iii] = true;
            it++, ft++;
            iii++;
        }
        ii++;
    }

    bitset<10> all;

    for (int i = 1; i < (1 << (adj[pos].size())); i++){

        all.set();


        for (size_t y = 0; y < adj[pos].size(); y++) {
            if (i & (1 << y)) all &= v[y];
        }
        // cout << i << " " << all << "\n";
        if (__builtin_popcount(i) == all.count()) output = max(output, __builtin_popcount(i) + 1);
    }

    for (int i : adj[pos]) adj[i].erase(pos);

    for (int i : adj[pos]) if ((int)adj[i].size() <= k) dfs(i);
}


int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);

    int n;
    cin >> n >> k;

    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a;

        for (int y = 0; y < a; y++)
        {
            cin >> b;
            adj[i].insert(b);
        }  
    }

    // for (int i = 0; i < n; i++)
    // {
    //     for (int y : adj[i]) cout << y << " ";
    //     cout << "\n";
    // }


    for (int i = 0; i < n; i++) if (!visited[i] && (int)adj[i].size() <= k) dfs(i);


    cout << output << "\n";

    cerr << clock() / static_cast<double>(CLOCKS_PER_SEC) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 6 ms 3156 KB Output is correct
4 Correct 12 ms 3180 KB Output is correct
5 Correct 14 ms 3156 KB Output is correct
6 Correct 5 ms 3176 KB Output is correct
7 Correct 6 ms 3156 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 6 ms 3156 KB Output is correct
4 Correct 12 ms 3180 KB Output is correct
5 Correct 14 ms 3156 KB Output is correct
6 Correct 5 ms 3176 KB Output is correct
7 Correct 6 ms 3156 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 9 ms 3156 KB Output is correct
12 Correct 12 ms 3156 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 31 ms 3156 KB Output is correct
15 Correct 2 ms 2648 KB Output is correct
16 Correct 5 ms 3156 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 6 ms 3160 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 3 ms 2924 KB Output is correct
21 Correct 3 ms 2900 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Execution timed out 3096 ms 3412 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2656 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Execution timed out 3071 ms 31948 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 6 ms 3156 KB Output is correct
4 Correct 12 ms 3180 KB Output is correct
5 Correct 14 ms 3156 KB Output is correct
6 Correct 5 ms 3176 KB Output is correct
7 Correct 6 ms 3156 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 9 ms 3156 KB Output is correct
12 Correct 12 ms 3156 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 31 ms 3156 KB Output is correct
15 Correct 2 ms 2648 KB Output is correct
16 Correct 5 ms 3156 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 6 ms 3160 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 3 ms 2924 KB Output is correct
21 Correct 3 ms 2900 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Execution timed out 3096 ms 3412 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 6 ms 3156 KB Output is correct
4 Correct 12 ms 3180 KB Output is correct
5 Correct 14 ms 3156 KB Output is correct
6 Correct 5 ms 3176 KB Output is correct
7 Correct 6 ms 3156 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 9 ms 3156 KB Output is correct
12 Correct 12 ms 3156 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 31 ms 3156 KB Output is correct
15 Correct 2 ms 2648 KB Output is correct
16 Correct 5 ms 3156 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 6 ms 3160 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 3 ms 2924 KB Output is correct
21 Correct 3 ms 2900 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Execution timed out 3096 ms 3412 KB Time limit exceeded
24 Halted 0 ms 0 KB -