Detachment HDU - 5976(染色法)

本文探讨了一个关于在无限维度空间中最大化多维空间体积的古老谜题。通过将一定长度的线段分割成多个不相等的部分,并将其分配到不同的维度来创建多维空间。目标是在遵循特定规则的情况下找到这个空间的最大可能体积。

In a highly developed alien society, the habitats are almost infinite dimensional space.
In the history of this planet,there is an old puzzle.
You have a line segment with x units’ length representing one dimension.The line segment can be split into a number of small line segments: a1,a2, … (x= a1+a2+…) assigned to different dimensions. And then, the multidimensional space has been established. Now there are two requirements for this space:
1.Two different small line segments cannot be equal ( ai≠aj when i≠j).
2.Make this multidimensional space size s as large as possible (s= a1∗a2

*...).Note that it allows to keep one dimension.That's to say, the number of ai can be only one.
Now can you solve this question and find the maximum size of the space?(For the final number is too large,your answer will be modulo 10^9+7)

Input

The first line is an integer T,meaning the number of test cases.
Then T lines follow. Each line contains one integer x.
1≤T≤10^6, 1≤x≤10^9

Output

Maximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.

Sample Input

1
4

Sample Output

4

题意:一共有n支球队,m场比赛,已经知道x个强队的编号,y个弱队的编号,已知每场比赛

都有一个强队和一个弱队,且不会出现即使强队又是弱队的情况,问能不能将所有队伍按强队弱队分开

思路:

一共强弱两个阵营,一场比赛有一个强队和一个弱队,强队和弱队之间建边,如果能分开,则构成的图是二分图

且所有点均被染色,否则,不能分开

代码:

#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int N = 1005;
const int M = 10005;
vector<int>G[N];
queue<int>p;
int arr[M*2],vis[N];
int ans,id;
int n,m,x,y;
void init(){
	id=ans=0;
	memset(vis,0,sizeof(vis));
	for(int i=0;i<=n;i++)
	   G[i].clear();
	while(!p.empty()) p.pop();
}
int BFS(){
	while(!p.empty()){
		int u=p.front();
	//	printf("%d ",u);
		p.pop();
		ans++;
		for(int i=0;i<G[u].size();i++){
			int v=G[u][i];
			if(vis[v]==vis[u]) return 0;
			if(vis[v]) continue;
			vis[v]=-vis[u];
			p.push(v);
		}
	}
	return 1;
}
int main(){
	while(~scanf("%d%d%d%d",&n,&m,&x,&y)){
		init();
		for(int i=0;i<m;i++){
			int u,v;
			scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
			arr[id++]=v;
			arr[id++]=u;
		}
	     for(int i=0;i<x;i++){
	     	int u;
	     	scanf("%d",&u);
	     	vis[u]=1;
	     	p.push(u);
		 }
		 for(int i=0;i<y;i++){
		 	int u;
	     	scanf("%d",&u);
	     	vis[u]=1;
	     	p.push(u);
		 }
		 int flag=BFS();
		 for(int i=0;i<id;i++){
		 	int u=arr[i];
		 	if(vis[u]) continue;
		 	vis[u]=1;
		 	p.push(u);
		 	flag=flag&&BFS();
		 }
		 if(ans==n&&flag) printf("YES\n");
		 else printf("NO\n");
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值