C. Anadi and Domino

题目链接:https://codeforces.com/contest/1230/problem/C

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.

 

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.

题意:每个指向顶点的点数是相同的,且每个骰子不能重复使用,问最多有几条边可以被摆放,其中可以用相同的点数指向不同的顶点

题解:如果顶点数小于等于6的话,肯定每个边都可以摆放。

那只要考虑有七个顶点的情况,肯定有一个点数是被两个顶点共用,如果这两个顶点还连接同一个顶点时,由于每个骰子只能使用一次,这两个边中肯定会有其中一条边被舍弃,所以枚举每两个顶点,有几个指向同一个顶点的就删去几个,找到最少的删除边,把其减去就是答案。

代码:

 #include <iostream>
#include <algorithm>
#include <cstdio>
#include<vector>
#include<string.h>
#include<queue>
#include<map>
#include<math.h>
#include<stdio.h>
#define inf 0x3f3f3f
#define ll long long
using namespace std;
int a[][]={};
int main()
{
int n,m;
cin>>n>>m;
for(int i=;i<=m;i++)
{
int p,q;
cin>>p>>q;
a[p][q]=a[q][p]=;
}int ans=inf,t;
if(n<=)
{
cout<<m<<endl;
return ;
}
else
{
for(int i=;i<;i++)
{
for(int j=i+;j<=;j++)
{
t=;
for(int k=;k<=;k++)
{ if(a[i][k]&&a[j][k])
{
t++;
}
}
ans=min(ans,t);
}
}
cout<<m-ans<<endl;
}
return ;
}

588 div2 C. Anadi and Domino的更多相关文章

  1. C. Anadi and Domino

    题目链接:http://codeforces.com/contest/1230/problem/C C. Anadi and Domino time limit per test: 2 seconds ...

  2. Anadi and Domino

    C - Anadi and Domino 参考:Anadi and Domino 思路:分为两种情况: ①n<=6,这个时候肯定可以保证降所有的边都放上一张多米诺牌,那么答案就是m ②n==7, ...

  3. Codeforces Round #588 (Div. 2) C. Anadi and Domino(思维)

    链接: https://codeforces.com/contest/1230/problem/C 题意: Anadi has a set of dominoes. Every domino has ...

  4. TopCoder SRM 588 DIV2 KeyDungeonDiv2

    简单的题目 class KeyDungeonDiv2 { public: int countDoors(vector <int> doorR, vector <int> doo ...

  5. CF1210A Anadi and Domino

    思路: 很有意思的思维题. 实现: #include <bits/stdc++.h> using namespace std; int check(vector<int>&am ...

  6. cf-1230C Anadi and Domino

    题目链接:http://codeforces.com/contest/1230/problem/C 题意: 有21 个多米诺骨牌,给定一个无向图(无自环,无重边),一条边上可以放一个多米诺骨牌.如果两 ...

  7. Codeforces Round #588 (Div. 2)

    传送门 A. Dawid and Bags of Candies 乱搞. Code #include <bits/stdc++.h> #define MP make_pair #defin ...

  8. codeforces刷题记录

    Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) C. Magic Grid 这种题直接构造 数n是2的n次方的倍数的时候可以这样划分数 ...

  9. Codeforces 238 div2 B. Domino Effect

    题目链接:http://codeforces.com/contest/405/problem/B 解题报告:一排n个的多米诺骨牌,规定,若从一边推的话多米诺骨牌会一直倒,但是如果从两个方向同时往中间推 ...

随机推荐

  1. CodeForces Round #514 (div2)

    A:Cashier 题意:问可以休息多少次. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen( ...

  2. Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  3. JavaScript new的运行过程

    参考 MDN网站的运算符 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/new new 运算符 ...

  4. Python 的整数与 Numpy 的数据溢出

    某位 A 同学发了我一张截图,问为何结果中出现了负数? 看了图,我第一感觉就是数据溢出了.数据超出能表示的最大值,就会出现奇奇怪怪的结果. 然后,他继续发了张图,内容是 print(100000*20 ...

  5. Docker Compose部署项目到容器-基于Tomcat和mysql的项目yml配置文件代码

    场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...

  6. 大数据平台搭建 - cdh5.11.1 - hbase集群搭建

    一.简介 HBase是一种构建在HDFS之上的分布式.面向列的存储系统.在需要实时读写.随机访问超大规模数据集时,可以使用HBase. 尽管已经有许多数据存储和访问的策略和实现方法,但事实上大多数解决 ...

  7. MockBean 单元测试

    案例一 官方文档:https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/reference/htmlsingle/ import org.juni ...

  8. 疑难杂症----Windows10

    现在大多数个人电脑所用的操作系统都是win10,而我们使用win10时总是会碰上各种各样的问题,所以专门写一篇博客来记录我碰上的各种问题,便于以后更快的解决问题. 一.小娜搜索不到应用问题解决方案 小 ...

  9. tlc549

    #include <reg51.h> #include "TLC549.c" code uchar seven_seg[] = {0xc0, 0xf9, 0xa4, 0 ...

  10. Thinkphp5.0 仿百度糯米 开发多商家 电商平台(完整版)

    目录第1章 课程简介第2章 需求分析第3章 快速掌握thinkphp5第4章 任性的TP5模块第5章 生活服务分类管理模块第6章 百度地图应用封装第7章 打造属于TP5自己的发送邮件服务第8章 商户模 ...