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;
} 

 

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