Codeforces Round #588 (Div. 2) C. 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≤61≤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 2121 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≤71≤n≤7, 0≤m≤n⋅(n−1)20≤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 ii-th line are aiai and bibi (1≤a,b≤n1≤a,b≤n, a≠ba≠b) and denote that there is an edge which connects vertices aiai and bibi.

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

Copy

4 4
1 2
2 3
3 4
4 1

output

Copy

4

input

Copy

7 0

output

Copy

0

input

Copy

3 1
1 3

output

Copy

1

input

Copy

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

Copy

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 11have three dots.

题意:

有21个骨牌,每个骨牌只能使用一次,下面给出一个无向图,没有自环,且两点之间只有一条边。每一个结点只能对应一个骨牌的值,每个边只能放一个骨牌,求可以在图的边上最多放多少个骨牌。

思路:

当n<7时,节点值正好和骨牌值对应,因此最多可以放m个;

当n=7时,必然有两个点骨牌值重复,若这两个点连接同一个点,则要删掉这两条边中的一个;列举所有可能性,取每种情况删掉的最小值。

代码如下:

 

代码如下:

#include<bits/stdc++.h>
using namespace std;
int a[10][10];
int main(){
	int n,m,c,b;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d %d",&b,&c);
		a[b][c]=1;
		a[c][b]=1;
	}
	if(n<7){
		printf("%d\n",m);
		return 0;
	}
	int minn=10000000;
	for(int i=1;i<8;i++){
		for(int j=i+1;j<8;j++){
			int cnt=0;
			for(int k=1;k<8;k++){
				if(a[i][k]&&a[j][k])cnt++;
			}
			minn=min(cnt,minn);
		}
	}
	printf("%d\n",m-minn);
	return 0;
} 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章