Anadi and Domino

Anadi and Domino

Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every aa and bb such that 1≤a≤b≤6, there is exactly one domino with aa dots on one half and bb dots on the other half. The set contains exactly 21 dominoes. Here is an exact illustration of his set:
                                       在这里插入图片描述
Also, Anadi has an undirected graph without self-loops and multiple edges. He wants to choose some dominoes and place them on the edges of this graph. He can use at most one domino of each type. Each edge can fit at most one domino. It’s not necessary to place a domino on each edge of the graph.

When placing a domino on an edge, he also chooses its direction. In other words, one half of any placed domino must be directed toward one of the endpoints of the edge and the other half must be directed toward the other endpoint. There’s a catch: if there are multiple halves of dominoes directed toward the same vertex, each of these halves must contain the same number of dots.

How many dominoes at most can Anadi place on the edges of his graph?

Input
The first line contains two integers nn and mm (1≤n≤7, 0≤m≤n⋅(n−1)/2) — the number of vertices and the number of edges in the graph.

The next mm lines contain two integers each. Integers in the i-th line are ai and bi (1≤a,b≤n,a≠b) and denote that there is an edge which connects vertices ai and bi.

The graph might be disconnected. It’s however guaranteed that the graph doesn’t contain any self-loops, and that there is at most one edge between any pair of vertices.

Output
Output one integer which denotes the maximum number of dominoes which Anadi can place on the edges of the graph.

Examples
input
4 4
1 2
2 3
3 4
4 1
output
4

input
7 0
output
0

input
3 1
1 3
output
1

input
7 21
1 2
1 3
1 4
1 5
1 6
1 7
2 3
2 4
2 5
2 6
2 7
3 4
3 5
3 6
3 7
4 5
4 6
4 7
5 6
5 7
6 7
output
16

Note
Here is an illustration of Anadi’s graph from the first sample test:
                                    在这里插入图片描述
And here is one of the ways to place a domino on each of its edges:

                                    在这里插入图片描述
Note that each vertex is faced by the halves of dominoes with the same number of dots. For instance, all halves directed toward vertex 1 have three dots.

思路:(依旧思维题)
我们可以将每个点的数字代表与这个点相连的骰子点数,那么问题可以分析为:
1.如果点数n<=6,那么对于任意两个点之前的边,都为一条且,可以在上面找到,此时所有的边都可以满足要求。
2.如果点数n=7,这个时候必然有一个点要重复两次,我们就可以进行枚举,判断任意两个点重复任意一个点的时候,重复的边的最小值,我们用总边数减一下就好了。

代码如下:

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mx=1e5+10;

int n,m;
int s[10][10];

int main(){
	memset(s,0,sizeof(s));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
    	int u,v;
    	scanf("%d%d",&u,&v);
    	s[u][v]=1;
    	s[v][u]=1;
    }
    if(n<7)
    printf("%d\n",m);
    else{
    	int ans=INF;
    	for(int i=1;i<=7;i++){//这两层for循环就是找到重复的点 
    		for(int j=i+1;j<=7;j++){
    			int cnt=0;
			    for(int k=1;k<=7;k++)//然后判断重复的边 
			    if(s[i][k]&&s[j][k])
			    cnt++;
			   	ans=min(ans,cnt);
		   }
	    }
	    printf("%d\n",m-ans);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值