답안 #939929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939929 2024-03-07T01:16:14 Z pcc Political Development (BOI17_politicaldevelopment) C++14
0 / 100
2 ms 4024 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>,less<pii>> pq;
int N,K;
vector<int> v;
int ans = 0;

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[b].push_back(i);
			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();

	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]++;
			}
		}
		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[j].find(k) == g[j].end())flag = false;
				}
			}
			if(flag)ans = max(ans,__builtin_popcount(i));
		}
	}
	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:70:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |    for(int j = 0;j<tar.size();j++){
      |                  ~^~~~~~~~~~~
politicaldevelopment.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(int k = j+1;k<tar.size();k++){
      |                     ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3932 KB Output isn't correct
2 Halted 0 ms 0 KB -