码迷,mamicode.com
首页 > 其他好文 > 详细

588 div2 C. Anadi and Domino

时间:2019-10-05 18:14:39      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:max   standard   img   from   amp   ges   技术   mem   pac   

 

C. Anadi and Domino

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

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

技术图片
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include<vector>
 5 #include<string.h>
 6 #include<queue>
 7 #include<map>
 8 #include<math.h>
 9 #include<stdio.h>
10 #define inf 0x3f3f3f
11 #define ll long long
12 using namespace std;
13 int a[10][10]={0};
14 int main()
15 {
16     int n,m;
17     cin>>n>>m;
18     for(int i=1;i<=m;i++)
19     {
20         int p,q;
21         cin>>p>>q;
22         a[p][q]=a[q][p]=1;
23     }int ans=inf,t;
24     if(n<=6)
25     {
26         cout<<m<<endl;
27         return 0;
28     }
29     else
30     {
31         for(int i=1;i<7;i++)
32         {
33             for(int j=i+1;j<=7;j++)//如果有七个顶点,则必有两个顶点共用相同的数字,所以枚举i,j是相同的数字,那么如果他们指向了同一端点则需要舍弃一个(每个骨牌只能用一次)
34             {
35                 t=0;
36                 for(int k=1;k<=7;k++)
37                 {
38 
39                     if(a[i][k]&&a[j][k])
40                     {
41                         t++;
42                     }
43                 }
44                 ans=min(ans,t);
45             }
46         }
47         cout<<m-ans<<endl;
48     }
49     return 0;
50 }
View Code

 

588 div2 C. Anadi and Domino

标签:max   standard   img   from   amp   ges   技术   mem   pac   

原文地址:https://www.cnblogs.com/thief-of-book/p/11625195.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!