@UPC 5065 @ICPC2017 Hua-Lian K : Assigning Frequencies (暴力枚举)

版权声明:岂曰无衣,与子同袍 https://blog.csdn.net/sizaif/article/details/82117362

Assigning Frequencies

时间限制: 2 Sec  内存限制: 128 MB
提交: 102  解决: 23
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Bob wants to assign frequencies to n satellites, numbered from 0 to n − 1. Two distinct satellites are said to be adjacent if, when assigned the same frequency, they interfere with each other. Sensibly, Bob’s assignment of frequencies must avoid interference altogether.
However, only three frequencies are available to him.
Please determine whether Bob can assign frequencies to all satellites to avoid any interference.

输入

The first line of the input contains an integer indicating the number of input cases. For each test case, the first line contains an integer n, denoting the number of satellites. The second line contains an integer p, denoting the number of adjacent pairs of satellites. The next p lines each contains two integers i, j, indicating the satellite i may intefer with satelite j when both are assigned the same frequency.

输出

For each test case, output “Y” if Bob can assign frequences so there is no integerence. Output “N” otherwise.

样例输入

4
6
6
0 3
1 5
3 2
2 5
0 4
1 0
7
12
6 5
0 3
2 6
3 5
5 0
0 4
4 5
6 3
1 4
1 2
3 4
2 3
7
8
6 5
0 3
2 6
3 5
1 4
1 2
3 4
2 3
6
9
0 1
1 2
2 3
5 2
5 3
3 4
2 4
1 4
4 5

样例输出

Y
N
Y
N

提示

1. There are at most 85 test cases
2. The number of satellites is n, n ≤ 25.

[题意]

有三个频率 ,  m个关系, 这m个关系 不能用统一频率, 问 能不能 让每个点都有频率,且 满足题意;

[思路]

 暴力枚举?   不是最大团?  , 呵 其实我们想的是  考虑度去边问题,..

[代码]

#include <bits/stdc++.h>
#include <stdio.h>

typedef long long ll;
#include <bits/stdc++.h>

const int N = 1000;
const int maxn = 1e5+10;

using namespace std;

int cot,mp[N][N];
int b[N];
int n,m;

bool dfs(int cur)
{
	for(int i = 0; i < cur; i++ )
	{
		if( mp[i][cur] && b[i]==b[cur])
			return false;
	}
	if(cur == n-1) return true;
	
	for(int i = 0; i <3 ;i++)
	{
		b[cur+1] = i;
		if( dfs(cur+1)) return true;
	}
	return false;
}
int main(int argc, char const *argv[])
{	
	int T;
	scanf("%d",&T);
	while(T--)
	{
		memset(mp,0,sizeof(mp));
		memset(b,0,sizeof(b));
		scanf("%d %d",&n,&m);
		while(m--)
		{
			int u,v;
			scanf("%d %d",&u,&v);
			mp[u][v] = mp[v][u] = 1 ;
		}
		if(dfs(0))
			printf("Y\n");
		else
			printf("N\n");
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/sizaif/article/details/82117362
UPC