Submission #469686

# Submission time Handle Problem Language Result Execution time Memory
469686 2021-09-01T15:25:21 Z wind_reaper Political Development (BOI17_politicaldevelopment) C++17
100 / 100
503 ms 26200 KB
#include <bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
*/

using namespace std;
// using namespace __gnu_pbds;
using namespace chrono;

// mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
/*
template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

//***************** CONSTANTS *****************

const int MXN = 50000;

//***************** GLOBAL VARIABLES *****************

set<int> g[MXN];
int D[MXN];

//***************** AUXILIARY STRUCTS *****************



//***************** MAIN BODY *****************

void solve(){
	int N, K;
	cin >> N >> K;

	priority_queue<array<int, 2>> pq;

	int sum = 0;

	for(int i = 0; i < N; i++){
		cin >> D[i];
		sum += D[i];
		for(int _ = 0; _ < D[i]; _++){
			int x;
			cin >> x;
			g[i].insert(x);
		}
		pq.push({-D[i], i});
	}

	assert(sum <= 2*N*K);
	
	int ans = 1;

	while(!pq.empty()){
		auto [deg, u] = pq.top();
		pq.pop();
		deg *= -1;

		if(deg != D[u])
			continue;

		vector<int> t(D[u]);
		int ptr = 0;
		for(int v : g[u]) t[ptr++] = v;

		for(int mask = 1; mask < (1 << deg); mask++){
			vector<int> vec;
			for(int i = 0; i < deg; i++)
				if((mask >> i) & 1)
					vec.push_back(t[i]);

			int k = vec.size();
			bool ok = true;

			for(int i = 0; i < k && ok; i++)
				for(int j = i + 1; j < k && ok; j++)
					if(g[vec[i]].find(vec[j]) == g[vec[i]].end()){
						ok = false;
						break;
					}

			if(ok) ans = max(ans, k + 1);
		}

		for(int v : g[u]){
			g[v].erase(u);
			D[v]--;
			pq.push({-D[v], v});
		}
	}

	cout << ans << '\n';
}

//***************** *****************

int32_t main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);

	#ifdef LOCAL
		auto begin = high_resolution_clock::now();
	#endif

	int tc = 1;
	// cin >> tc; 
	for (int t = 0; t < tc; t++)
		solve();

	#ifdef LOCAL 
		auto end = high_resolution_clock::now();
		cout << fixed << setprecision(4);
		cout << "Execution Time: " << duration_cast<duration<double>>(end - begin).count() << "seconds" << endl;
	#endif

	return 0;
}

/*
If code gives a WA, check for the following : 
1. I/O format

2. Are you clearing all global variables in between tests if multitests are a thing

3. Can you definitively prove the logic

4. If the code gives an inexplicable TLE, and you are sure you have the best possible complexity,
use faster io
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 7 ms 3264 KB Output is correct
4 Correct 7 ms 3148 KB Output is correct
5 Correct 6 ms 3148 KB Output is correct
6 Correct 6 ms 3268 KB Output is correct
7 Correct 6 ms 3148 KB Output is correct
8 Correct 3 ms 2764 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 3 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 7 ms 3264 KB Output is correct
4 Correct 7 ms 3148 KB Output is correct
5 Correct 6 ms 3148 KB Output is correct
6 Correct 6 ms 3268 KB Output is correct
7 Correct 6 ms 3148 KB Output is correct
8 Correct 3 ms 2764 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 3 ms 2764 KB Output is correct
11 Correct 6 ms 3208 KB Output is correct
12 Correct 6 ms 3148 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 6 ms 3148 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 6 ms 3196 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 6 ms 3204 KB Output is correct
19 Correct 3 ms 2764 KB Output is correct
20 Correct 4 ms 2964 KB Output is correct
21 Correct 4 ms 2968 KB Output is correct
22 Correct 3 ms 2764 KB Output is correct
23 Correct 8 ms 3276 KB Output is correct
24 Correct 3 ms 2764 KB Output is correct
25 Correct 10 ms 3320 KB Output is correct
26 Correct 7 ms 3148 KB Output is correct
27 Correct 6 ms 3148 KB Output is correct
28 Correct 7 ms 3148 KB Output is correct
29 Correct 6 ms 3148 KB Output is correct
30 Correct 8 ms 3276 KB Output is correct
31 Correct 7 ms 3276 KB Output is correct
32 Correct 10 ms 3372 KB Output is correct
33 Correct 8 ms 3364 KB Output is correct
34 Correct 8 ms 3328 KB Output is correct
35 Correct 4 ms 2892 KB Output is correct
36 Correct 5 ms 2892 KB Output is correct
37 Correct 4 ms 2892 KB Output is correct
38 Correct 4 ms 2892 KB Output is correct
39 Correct 5 ms 2892 KB Output is correct
40 Correct 14 ms 3748 KB Output is correct
41 Correct 4 ms 2892 KB Output is correct
42 Correct 11 ms 3664 KB Output is correct
43 Correct 11 ms 3696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2764 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 488 ms 25936 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 493 ms 26040 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 492 ms 26200 KB Output is correct
16 Correct 488 ms 25932 KB Output is correct
17 Correct 490 ms 25956 KB Output is correct
18 Correct 488 ms 26036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 7 ms 3264 KB Output is correct
4 Correct 7 ms 3148 KB Output is correct
5 Correct 6 ms 3148 KB Output is correct
6 Correct 6 ms 3268 KB Output is correct
7 Correct 6 ms 3148 KB Output is correct
8 Correct 3 ms 2764 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 3 ms 2764 KB Output is correct
11 Correct 6 ms 3208 KB Output is correct
12 Correct 6 ms 3148 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 6 ms 3148 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 6 ms 3196 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 6 ms 3204 KB Output is correct
19 Correct 3 ms 2764 KB Output is correct
20 Correct 4 ms 2964 KB Output is correct
21 Correct 4 ms 2968 KB Output is correct
22 Correct 3 ms 2764 KB Output is correct
23 Correct 8 ms 3276 KB Output is correct
24 Correct 3 ms 2764 KB Output is correct
25 Correct 10 ms 3320 KB Output is correct
26 Correct 7 ms 3148 KB Output is correct
27 Correct 6 ms 3148 KB Output is correct
28 Correct 7 ms 3148 KB Output is correct
29 Correct 6 ms 3148 KB Output is correct
30 Correct 8 ms 3276 KB Output is correct
31 Correct 7 ms 3276 KB Output is correct
32 Correct 10 ms 3372 KB Output is correct
33 Correct 8 ms 3364 KB Output is correct
34 Correct 8 ms 3328 KB Output is correct
35 Correct 4 ms 2892 KB Output is correct
36 Correct 5 ms 2892 KB Output is correct
37 Correct 4 ms 2892 KB Output is correct
38 Correct 4 ms 2892 KB Output is correct
39 Correct 5 ms 2892 KB Output is correct
40 Correct 14 ms 3748 KB Output is correct
41 Correct 4 ms 2892 KB Output is correct
42 Correct 11 ms 3664 KB Output is correct
43 Correct 11 ms 3696 KB Output is correct
44 Correct 74 ms 4588 KB Output is correct
45 Correct 2 ms 2636 KB Output is correct
46 Correct 11 ms 3660 KB Output is correct
47 Correct 26 ms 4876 KB Output is correct
48 Correct 13 ms 3696 KB Output is correct
49 Correct 32 ms 4880 KB Output is correct
50 Correct 28 ms 4812 KB Output is correct
51 Correct 238 ms 6988 KB Output is correct
52 Correct 6 ms 3128 KB Output is correct
53 Correct 484 ms 7592 KB Output is correct
54 Correct 478 ms 7424 KB Output is correct
55 Correct 8 ms 3148 KB Output is correct
56 Correct 6 ms 3204 KB Output is correct
57 Correct 4 ms 2764 KB Output is correct
58 Correct 503 ms 7420 KB Output is correct
59 Correct 11 ms 3660 KB Output is correct
60 Correct 7 ms 3204 KB Output is correct
61 Correct 11 ms 3640 KB Output is correct
62 Correct 11 ms 3668 KB Output is correct
63 Correct 73 ms 4540 KB Output is correct
64 Correct 41 ms 4300 KB Output is correct
65 Correct 13 ms 3532 KB Output is correct
66 Correct 11 ms 3660 KB Output is correct
67 Correct 60 ms 5220 KB Output is correct
68 Correct 48 ms 4456 KB Output is correct
69 Correct 10 ms 3532 KB Output is correct
70 Correct 31 ms 4564 KB Output is correct
71 Correct 56 ms 5084 KB Output is correct
72 Correct 48 ms 5140 KB Output is correct
73 Correct 6 ms 3148 KB Output is correct
74 Correct 25 ms 4532 KB Output is correct
75 Correct 46 ms 5156 KB Output is correct
76 Correct 15 ms 4044 KB Output is correct
77 Correct 98 ms 5756 KB Output is correct
78 Correct 6 ms 3148 KB Output is correct
79 Correct 55 ms 4160 KB Output is correct
80 Correct 16 ms 4044 KB Output is correct
81 Correct 95 ms 5648 KB Output is correct
82 Correct 4 ms 2892 KB Output is correct
83 Correct 48 ms 4164 KB Output is correct
84 Correct 44 ms 5096 KB Output is correct
85 Correct 4 ms 2892 KB Output is correct
86 Correct 44 ms 5156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 7 ms 3264 KB Output is correct
4 Correct 7 ms 3148 KB Output is correct
5 Correct 6 ms 3148 KB Output is correct
6 Correct 6 ms 3268 KB Output is correct
7 Correct 6 ms 3148 KB Output is correct
8 Correct 3 ms 2764 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 3 ms 2764 KB Output is correct
11 Correct 6 ms 3208 KB Output is correct
12 Correct 6 ms 3148 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 6 ms 3148 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 6 ms 3196 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 6 ms 3204 KB Output is correct
19 Correct 3 ms 2764 KB Output is correct
20 Correct 4 ms 2964 KB Output is correct
21 Correct 4 ms 2968 KB Output is correct
22 Correct 3 ms 2764 KB Output is correct
23 Correct 8 ms 3276 KB Output is correct
24 Correct 3 ms 2764 KB Output is correct
25 Correct 10 ms 3320 KB Output is correct
26 Correct 7 ms 3148 KB Output is correct
27 Correct 6 ms 3148 KB Output is correct
28 Correct 7 ms 3148 KB Output is correct
29 Correct 6 ms 3148 KB Output is correct
30 Correct 8 ms 3276 KB Output is correct
31 Correct 7 ms 3276 KB Output is correct
32 Correct 10 ms 3372 KB Output is correct
33 Correct 8 ms 3364 KB Output is correct
34 Correct 8 ms 3328 KB Output is correct
35 Correct 4 ms 2892 KB Output is correct
36 Correct 5 ms 2892 KB Output is correct
37 Correct 4 ms 2892 KB Output is correct
38 Correct 4 ms 2892 KB Output is correct
39 Correct 5 ms 2892 KB Output is correct
40 Correct 14 ms 3748 KB Output is correct
41 Correct 4 ms 2892 KB Output is correct
42 Correct 11 ms 3664 KB Output is correct
43 Correct 11 ms 3696 KB Output is correct
44 Correct 2 ms 2636 KB Output is correct
45 Correct 217 ms 18888 KB Output is correct
46 Correct 93 ms 10356 KB Output is correct
47 Correct 219 ms 18972 KB Output is correct
48 Correct 202 ms 18892 KB Output is correct
49 Correct 54 ms 7868 KB Output is correct
50 Correct 278 ms 23680 KB Output is correct
51 Correct 214 ms 18972 KB Output is correct
52 Correct 52 ms 7876 KB Output is correct
53 Correct 51 ms 7816 KB Output is correct
54 Correct 12 ms 3408 KB Output is correct
55 Correct 324 ms 23656 KB Output is correct
56 Correct 30 ms 5572 KB Output is correct
57 Correct 53 ms 7864 KB Output is correct
58 Correct 77 ms 10300 KB Output is correct
59 Correct 29 ms 5516 KB Output is correct
60 Correct 29 ms 5572 KB Output is correct
61 Correct 72 ms 10176 KB Output is correct
62 Correct 52 ms 7936 KB Output is correct
63 Correct 104 ms 12100 KB Output is correct
64 Correct 30 ms 5572 KB Output is correct
65 Correct 152 ms 14448 KB Output is correct
66 Correct 51 ms 7860 KB Output is correct
67 Correct 105 ms 12088 KB Output is correct
68 Correct 128 ms 13832 KB Output is correct
69 Correct 144 ms 14416 KB Output is correct
70 Correct 52 ms 7828 KB Output is correct
71 Correct 131 ms 13832 KB Output is correct
72 Correct 131 ms 11708 KB Output is correct
73 Correct 166 ms 15932 KB Output is correct
74 Correct 46 ms 7896 KB Output is correct
75 Correct 51 ms 7856 KB Output is correct
76 Correct 105 ms 11604 KB Output is correct
77 Correct 158 ms 15932 KB Output is correct
78 Correct 72 ms 9244 KB Output is correct
79 Correct 65 ms 7800 KB Output is correct
80 Correct 25 ms 5196 KB Output is correct
81 Correct 75 ms 9280 KB Output is correct
82 Correct 115 ms 13260 KB Output is correct
83 Correct 24 ms 5268 KB Output is correct
84 Correct 115 ms 13260 KB Output is correct