QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#1457#283754#7514. Clique ChallengeEdward2019PhantomThresholdSuccess!2025-01-18 20:43:242025-01-18 20:43:24

详细

Extra Test:

Time Limit Exceeded

input:

45 990
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
2 16
2 17
2 18
2 19
2 2...

output:


result:


ID题目提交者结果用时内存语言文件大小提交时间测评时间
#283754#7514. Clique ChallengePhantomThresholdTL 521ms134584kbC++202.1kb2023-12-15 13:09:592025-01-18 21:21:54

answer

#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int main()
{
	ios_base::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<vector<int>> G(n+5);
	vector<int> deg(n+5);
	vector<pair<int,int>> edges;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		deg[u]++;deg[v]++;
		G[u].push_back(v);G[v].push_back(u);
		edges.emplace_back(u,v);
	}
	vector<int> ord(n+5);
	iota(ord.begin(),ord.end(),0);
	sort(ord.begin()+1,ord.begin()+n+1,[&](int x,int y){return deg[x]==deg[y]?x<y:deg[x]<deg[y];});
	vector<int> pos(n+5);
	for(int i=1;i<=n;i++)pos[ord[i]]=i;
	long long ans=0;
	auto solve=[&](auto &a,auto t)
	{
		/*
		cerr<<"solve"<<endl;
		for(int i=1;i<=t;i++)
		{
			for(int j=1;j<=t;j++)
				cerr<<((a[i]>>j)&1);
			cerr<<endl;
		}
		*/
		int hf=(t+1)/2,rem=t-hf;
		vector<long long> L(1<<hf),Ls(1<<hf),R(1<<rem),Rs(1<<rem);
		R[0]=1;
		Rs[0]=((1<<rem)-1);
		for(int i=0;i<(1<<rem);i++)
		{
			if(not R[i])continue;
			int tmp=Rs[i];
			for(int j;tmp;tmp&=~(1<<j))
			{
				j=31-__builtin_clz(tmp);
				R[i|(1<<j)]=1;
				Rs[i|(1<<j)]=Rs[i]&(a[j+hf+1]>>(hf+1))&~(1<<j);
			}
		}
		for(int j=0;j<rem;j++)
			for(int i=0;i<(1<<rem);i++)
				if(not ((i>>j)&1))
					R[i|(1<<j)]+=R[i];
		L[0]=1;
		Ls[0]=((1ll<<t)-1);
		for(int i=0;i<(1<<hf);i++)
		{
			if(not L[i])continue;
			int tmp=Ls[i]&((1<<hf)-1);
			for(int j;tmp;tmp&=~(1<<j))
			{
				j=31-__builtin_clz(tmp);
				L[i|(1<<j)]=1;
				Ls[i|(1<<j)]=Ls[i]&(a[j+1]>>1)&~(1<<j);
			}
			if(i&1)
			{
//				cerr<<"subset "<<i<<" add "<<R[Ls[i]>>hf]<<endl;
				ans+=R[Ls[i]>>hf];
			}
		}
	};
	for(int i=1;i<=n;i++)
	{
		vector<int> idx(n+5);
		int x=ord[i];
//		cerr<<"order "<<i<<' '<<x<<endl;
		int t=1;
		idx[x]=t;
		for(auto v:G[x])
		{
			if(pos[v]>pos[x])
			{
				++t;
				idx[v]=t;
			}
		}
		vector<long long> a(t+5);
		for(auto [u,v]:edges)
		{
			if(idx[u] and idx[v])
			{
//				cerr<<"addedge "<<idx[u]<<' '<<idx[v]<<endl;
				a[idx[u]]|=(1ll<<idx[v]);
				a[idx[v]]|=(1ll<<idx[u]);
			}
		}
		solve(a,t);
	}
	cout<<ans%MOD<<endl;
	return 0;
}