답안 #939932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939932 2024-03-07T01:31:30 Z pcc Political Development (BOI17_politicaldevelopment) C++14
100 / 100
1271 ms 33928 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


const int mxn = 5e4+10;
vector<int> paths[mxn];
set<int> g[mxn];
bitset<mxn> vis;
int deg[mxn];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int N,K;
vector<int> v;
int ans = 1;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>K;
	for(int i = 0;i<N;i++){
		int m;
		cin>>m;
		while(m--){
			int b;
			cin>>b;
			paths[i].push_back(b);
			deg[i]++,deg[b]++;
		}
	}
	for(int i = 0;i<N;i++)pq.push(pii(deg[i],i));
	while(!pq.empty()){
		auto now = pq.top().sc;
		pq.pop();
		if(vis[now])continue;
		vis[now] = true;
		v.push_back(now);
		for(auto nxt:paths[now]){
			deg[nxt]--;
			if(!vis[nxt])pq.push({deg[nxt],nxt});
		}
	}
	reverse(v.begin(),v.end());
	vis.reset();
	memset(deg,0,sizeof(deg));

	for(auto &now:v){
		assert(g[now].size()<K);
		vis[now] = true;
		vector<int> vv;
		for(auto &nxt:paths[now]){
			if(vis[nxt]){
				vv.push_back(nxt);
				g[now].insert(nxt);
				g[nxt].insert(now);
				deg[now]++;
				deg[nxt]++;
			}
		}
		//cerr<<now<<":"<<deg[now]<<endl; 
		for(int i = 1;i<(1<<deg[now]);i++){
			vector<int> tar;
			for(int j = 0;j<deg[now];j++){
				if(i&(1<<j))tar.push_back(vv[j]);
			}
			bool flag = true;
			for(int j = 0;j<tar.size();j++){
				for(int k = j+1;k<tar.size();k++){
					if(g[tar[j]].find(tar[k]) == g[tar[j]].end())flag = false;
				}
			}
			if(flag)ans = max(ans,(int)tar.size()+1);
		}
	}
	cout<<ans;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from politicaldevelopment.cpp:1:
politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:52:23: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |   assert(g[now].size()<K);
      |          ~~~~~~~~~~~~~^~
politicaldevelopment.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |    for(int j = 0;j<tar.size();j++){
      |                  ~^~~~~~~~~~~
politicaldevelopment.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int k = j+1;k<tar.size();k++){
      |                     ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4340 KB Output is correct
2 Correct 1 ms 3932 KB Output is correct
3 Correct 5 ms 4828 KB Output is correct
4 Correct 5 ms 4956 KB Output is correct
5 Correct 5 ms 4976 KB Output is correct
6 Correct 4 ms 4956 KB Output is correct
7 Correct 4 ms 4796 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 1 ms 3932 KB Output is correct
10 Correct 2 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4340 KB Output is correct
2 Correct 1 ms 3932 KB Output is correct
3 Correct 5 ms 4828 KB Output is correct
4 Correct 5 ms 4956 KB Output is correct
5 Correct 5 ms 4976 KB Output is correct
6 Correct 4 ms 4956 KB Output is correct
7 Correct 4 ms 4796 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 1 ms 3932 KB Output is correct
10 Correct 2 ms 4184 KB Output is correct
11 Correct 4 ms 4952 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 1 ms 3932 KB Output is correct
14 Correct 4 ms 4956 KB Output is correct
15 Correct 1 ms 3932 KB Output is correct
16 Correct 4 ms 4956 KB Output is correct
17 Correct 2 ms 3932 KB Output is correct
18 Correct 4 ms 4908 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 3 ms 4464 KB Output is correct
21 Correct 3 ms 4536 KB Output is correct
22 Correct 2 ms 4188 KB Output is correct
23 Correct 6 ms 4960 KB Output is correct
24 Correct 2 ms 4188 KB Output is correct
25 Correct 5 ms 4956 KB Output is correct
26 Correct 5 ms 4952 KB Output is correct
27 Correct 4 ms 4952 KB Output is correct
28 Correct 5 ms 4952 KB Output is correct
29 Correct 4 ms 4952 KB Output is correct
30 Correct 6 ms 4956 KB Output is correct
31 Correct 6 ms 5208 KB Output is correct
32 Correct 5 ms 4908 KB Output is correct
33 Correct 6 ms 4912 KB Output is correct
34 Correct 6 ms 4956 KB Output is correct
35 Correct 3 ms 4420 KB Output is correct
36 Correct 4 ms 4444 KB Output is correct
37 Correct 4 ms 4444 KB Output is correct
38 Correct 3 ms 4336 KB Output is correct
39 Correct 3 ms 4444 KB Output is correct
40 Correct 8 ms 5468 KB Output is correct
41 Correct 3 ms 4444 KB Output is correct
42 Correct 8 ms 5468 KB Output is correct
43 Correct 8 ms 5468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4008 KB Output is correct
3 Correct 1 ms 4188 KB Output is correct
4 Correct 1 ms 4188 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 2 ms 4188 KB Output is correct
10 Correct 1 ms 4184 KB Output is correct
11 Correct 560 ms 33928 KB Output is correct
12 Correct 1 ms 4188 KB Output is correct
13 Correct 506 ms 33760 KB Output is correct
14 Correct 1 ms 4188 KB Output is correct
15 Correct 517 ms 33824 KB Output is correct
16 Correct 504 ms 33724 KB Output is correct
17 Correct 508 ms 33652 KB Output is correct
18 Correct 558 ms 33636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4340 KB Output is correct
2 Correct 1 ms 3932 KB Output is correct
3 Correct 5 ms 4828 KB Output is correct
4 Correct 5 ms 4956 KB Output is correct
5 Correct 5 ms 4976 KB Output is correct
6 Correct 4 ms 4956 KB Output is correct
7 Correct 4 ms 4796 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 1 ms 3932 KB Output is correct
10 Correct 2 ms 4184 KB Output is correct
11 Correct 4 ms 4952 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 1 ms 3932 KB Output is correct
14 Correct 4 ms 4956 KB Output is correct
15 Correct 1 ms 3932 KB Output is correct
16 Correct 4 ms 4956 KB Output is correct
17 Correct 2 ms 3932 KB Output is correct
18 Correct 4 ms 4908 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 3 ms 4464 KB Output is correct
21 Correct 3 ms 4536 KB Output is correct
22 Correct 2 ms 4188 KB Output is correct
23 Correct 6 ms 4960 KB Output is correct
24 Correct 2 ms 4188 KB Output is correct
25 Correct 5 ms 4956 KB Output is correct
26 Correct 5 ms 4952 KB Output is correct
27 Correct 4 ms 4952 KB Output is correct
28 Correct 5 ms 4952 KB Output is correct
29 Correct 4 ms 4952 KB Output is correct
30 Correct 6 ms 4956 KB Output is correct
31 Correct 6 ms 5208 KB Output is correct
32 Correct 5 ms 4908 KB Output is correct
33 Correct 6 ms 4912 KB Output is correct
34 Correct 6 ms 4956 KB Output is correct
35 Correct 3 ms 4420 KB Output is correct
36 Correct 4 ms 4444 KB Output is correct
37 Correct 4 ms 4444 KB Output is correct
38 Correct 3 ms 4336 KB Output is correct
39 Correct 3 ms 4444 KB Output is correct
40 Correct 8 ms 5468 KB Output is correct
41 Correct 3 ms 4444 KB Output is correct
42 Correct 8 ms 5468 KB Output is correct
43 Correct 8 ms 5468 KB Output is correct
44 Correct 62 ms 6484 KB Output is correct
45 Correct 1 ms 4184 KB Output is correct
46 Correct 8 ms 5464 KB Output is correct
47 Correct 25 ms 6416 KB Output is correct
48 Correct 8 ms 5468 KB Output is correct
49 Correct 24 ms 6516 KB Output is correct
50 Correct 31 ms 6540 KB Output is correct
51 Correct 555 ms 9008 KB Output is correct
52 Correct 4 ms 4952 KB Output is correct
53 Correct 867 ms 10300 KB Output is correct
54 Correct 1271 ms 9708 KB Output is correct
55 Correct 4 ms 4956 KB Output is correct
56 Correct 4 ms 4956 KB Output is correct
57 Correct 2 ms 4188 KB Output is correct
58 Correct 823 ms 9684 KB Output is correct
59 Correct 8 ms 5212 KB Output is correct
60 Correct 4 ms 4956 KB Output is correct
61 Correct 8 ms 5212 KB Output is correct
62 Correct 8 ms 5208 KB Output is correct
63 Correct 63 ms 6380 KB Output is correct
64 Correct 33 ms 6224 KB Output is correct
65 Correct 7 ms 5212 KB Output is correct
66 Correct 7 ms 5212 KB Output is correct
67 Correct 66 ms 7036 KB Output is correct
68 Correct 33 ms 6152 KB Output is correct
69 Correct 7 ms 5212 KB Output is correct
70 Correct 22 ms 6208 KB Output is correct
71 Correct 63 ms 6996 KB Output is correct
72 Correct 52 ms 6992 KB Output is correct
73 Correct 4 ms 4952 KB Output is correct
74 Correct 23 ms 6488 KB Output is correct
75 Correct 62 ms 6864 KB Output is correct
76 Correct 12 ms 5724 KB Output is correct
77 Correct 142 ms 7776 KB Output is correct
78 Correct 4 ms 4696 KB Output is correct
79 Correct 75 ms 6336 KB Output is correct
80 Correct 15 ms 5724 KB Output is correct
81 Correct 148 ms 7564 KB Output is correct
82 Correct 3 ms 4444 KB Output is correct
83 Correct 74 ms 5816 KB Output is correct
84 Correct 46 ms 6896 KB Output is correct
85 Correct 3 ms 4444 KB Output is correct
86 Correct 45 ms 7100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4340 KB Output is correct
2 Correct 1 ms 3932 KB Output is correct
3 Correct 5 ms 4828 KB Output is correct
4 Correct 5 ms 4956 KB Output is correct
5 Correct 5 ms 4976 KB Output is correct
6 Correct 4 ms 4956 KB Output is correct
7 Correct 4 ms 4796 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 1 ms 3932 KB Output is correct
10 Correct 2 ms 4184 KB Output is correct
11 Correct 4 ms 4952 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 1 ms 3932 KB Output is correct
14 Correct 4 ms 4956 KB Output is correct
15 Correct 1 ms 3932 KB Output is correct
16 Correct 4 ms 4956 KB Output is correct
17 Correct 2 ms 3932 KB Output is correct
18 Correct 4 ms 4908 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 3 ms 4464 KB Output is correct
21 Correct 3 ms 4536 KB Output is correct
22 Correct 2 ms 4188 KB Output is correct
23 Correct 6 ms 4960 KB Output is correct
24 Correct 2 ms 4188 KB Output is correct
25 Correct 5 ms 4956 KB Output is correct
26 Correct 5 ms 4952 KB Output is correct
27 Correct 4 ms 4952 KB Output is correct
28 Correct 5 ms 4952 KB Output is correct
29 Correct 4 ms 4952 KB Output is correct
30 Correct 6 ms 4956 KB Output is correct
31 Correct 6 ms 5208 KB Output is correct
32 Correct 5 ms 4908 KB Output is correct
33 Correct 6 ms 4912 KB Output is correct
34 Correct 6 ms 4956 KB Output is correct
35 Correct 3 ms 4420 KB Output is correct
36 Correct 4 ms 4444 KB Output is correct
37 Correct 4 ms 4444 KB Output is correct
38 Correct 3 ms 4336 KB Output is correct
39 Correct 3 ms 4444 KB Output is correct
40 Correct 8 ms 5468 KB Output is correct
41 Correct 3 ms 4444 KB Output is correct
42 Correct 8 ms 5468 KB Output is correct
43 Correct 8 ms 5468 KB Output is correct
44 Correct 2 ms 3932 KB Output is correct
45 Correct 141 ms 23400 KB Output is correct
46 Correct 61 ms 14556 KB Output is correct
47 Correct 171 ms 23428 KB Output is correct
48 Correct 141 ms 23240 KB Output is correct
49 Correct 30 ms 11724 KB Output is correct
50 Correct 242 ms 29292 KB Output is correct
51 Correct 158 ms 23388 KB Output is correct
52 Correct 34 ms 11728 KB Output is correct
53 Correct 31 ms 11852 KB Output is correct
54 Correct 8 ms 5080 KB Output is correct
55 Correct 223 ms 29212 KB Output is correct
56 Correct 24 ms 8908 KB Output is correct
57 Correct 35 ms 11760 KB Output is correct
58 Correct 53 ms 14088 KB Output is correct
59 Correct 20 ms 8920 KB Output is correct
60 Correct 20 ms 8920 KB Output is correct
61 Correct 50 ms 14296 KB Output is correct
62 Correct 46 ms 11672 KB Output is correct
63 Correct 68 ms 15816 KB Output is correct
64 Correct 20 ms 8908 KB Output is correct
65 Correct 95 ms 18892 KB Output is correct
66 Correct 33 ms 11472 KB Output is correct
67 Correct 67 ms 15976 KB Output is correct
68 Correct 92 ms 17960 KB Output is correct
69 Correct 93 ms 18920 KB Output is correct
70 Correct 31 ms 11564 KB Output is correct
71 Correct 91 ms 18192 KB Output is correct
72 Correct 71 ms 15520 KB Output is correct
73 Correct 111 ms 20712 KB Output is correct
74 Correct 33 ms 11476 KB Output is correct
75 Correct 36 ms 10444 KB Output is correct
76 Correct 65 ms 15432 KB Output is correct
77 Correct 123 ms 20680 KB Output is correct
78 Correct 52 ms 12520 KB Output is correct
79 Correct 35 ms 10440 KB Output is correct
80 Correct 17 ms 7416 KB Output is correct
81 Correct 53 ms 12440 KB Output is correct
82 Correct 71 ms 17604 KB Output is correct
83 Correct 20 ms 7420 KB Output is correct
84 Correct 79 ms 17092 KB Output is correct