题意:给你一个有趣图的定义:在这个图中有一个根,根与每个点都有边和回边,除了根之外,其他的点的出度和入度都为2,然后给你一个图让你经过几步操作可以使此图变为有趣图,操作为:删边或者加边。

思路:枚举根,然后删除与根有关的边,重新建图,用二分图求最大匹配,可以用匈牙利算法,加的边数:满足题中有关根的加边数+(点数-匹配数),删掉的边数:边数-满足题中有关根的使用的边数-匹配时使用的边数。

 #include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int inf=<<; int g[][];
int n,m;
bool chk[];
int match[];
vector<int>x[]; int dfs(int p)
{
for(int i=; i<(int)x[p].size(); i++)
{
int v=x[p][i];
if(!chk[v])
{
chk[v]=true;
int t=match[v];
match[v]=p;
if(t==-||dfs(t))
{
return ;
}
match[v]=t;
}
}
return ;
} int Pro(int c)
{
memset(match,-,sizeof(match));
int res=;
for(int i=; i<=n; i++)
{
if(i==c) continue;
memset(chk,false,sizeof(chk));
res+=dfs(i);
}
return res;
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
vector<int>gg[];
for(int i=; i<=m; i++)
{
int u,v;
scanf("%d%d",&u,&v);
gg[u].push_back(v);
g[u][v]=;
}
int ans=inf;
for(int i=; i<=n; i++)
{
int t1=n-gg[i].size();
for(int j=; j<=n; j++)
{
if(!g[j][i]) t1++;
}
if(g[i][i]==) t1--;
for(int j=; j<=n; j++)
{
x[j].clear();
}
int cnt=;
for(int j=; j<=n; j++)
{
if(j==i) continue;
for(int k=; k<(int)gg[j].size(); k++)
{
int v=gg[j][k];
if(v==i)continue;
cnt++;
x[j].push_back(v);
}
}
ans=min(ans,t1+cnt+n--*Pro(i));
}
printf("%d\n",ans);
}
return ;
}

cf D George and Interesting Graph的更多相关文章

  1. 【CF387D】George and Interesting Graph(二分图最大匹配)

    题意:给定一张n点m边没有重边的有向图,定义一个有趣图为:存在一个中心点满足以下性质: 1.除了这个中心点之外其他的点都要满足存在两个出度和两个入度. 2.中心 u 需要对任意顶点 v(包括自己)有一 ...

  2. Codeforces 916C - Jamie and Interesting Graph

    916C - Jamie and Interesting Graph 思路:构造. 对于1到n最短路且素数,那么1到n之间连2 对于最小生成树,找一个稍微大点的素数(比1e5大)构造一个和为这个素数的 ...

  3. Codeforces Beta Round #9 (Div. 2 Only) E. Interesting Graph and Apples 构造题

    E. Interesting Graph and Apples 题目连接: http://www.codeforces.com/contest/9/problem/E Description Hexa ...

  4. cf B George and Cards

    题意:给你一个只有‘.’和'#'的n*n的格子,问所有的'#'是不是只属于一个十字叉,如果不是输出NO,否则输出YES. #include <cstdio> #include <cs ...

  5. cf E. George and Cards

    http://codeforces.com/contest/387/problem/E 题意:给你n个数,然后在输入k个数,这k个数都在n个数中出现,进行每一次操作就是在n个数中选择长度为w的连续序列 ...

  6. cf C. George and Number

    http://codeforces.com/problemset/problem/387/C 题意:给你一个大数,让你求个集合,可以通过操作得到这个数,求集合中个数最大值,操作 :从集合中任意取两个数 ...

  7. cf B George and Round

    题意:输入n,m,下一行为n个数a1<a2<a3......<an:然后再输入m个数b1<=b2<=b3<.....<=bm: 每个ai都必须在b中找到相等的 ...

  8. cf D. Dima and Trap Graph

    http://codeforces.com/contest/366/problem/D 遍历下界,然后用二分求上界,然后用dfs去判断是否可以. #include <cstdio> #in ...

  9. CodeForces 916C Jamie and Interesting Graph (构造)

    题意:给定两个数,表示一个图的点数和边数,让你构造出一个图满足 1-  n 的最短路是素数,并且最小生成树也是素数. 析:首先 1 - n 的最短路,非常好解决,直接 1 连 n 就好了,但是素数尽量 ...

随机推荐

  1. Apache SSL服务器配置SSL详解(转)

    1.安装必要的软件 引用 我用的是apahce2.0.61版,可以直接官方提供的绑定openssl的apache. 文件名是:apache_2.0.61-win32-x86-openssl-0.9.7 ...

  2. agentzh --春哥--调试专家

    https://github.com/agentzh/perl-systemtap-toolkit https://github.com/openresty http://openresty.org/ ...

  3. Tomcat7.0.40 基于DataSourceRealm的和JDBCRealm的资源用户访问控制

    软件版本: Tomcat 7.0.40 Mysql: 5.1 Host: CentOS 6.3 64bit 使用JDBCRealm (Tomcat 会使用所给的JDBC Connecter 自己去连M ...

  4. 再回首,Java温故知新(九):Java基础之流程控制语句

    流程控制语句分为条件语句.循环语句和中断语句. 中断语句包括break和continue,两者的区别在于break会跳出整个循环,而continue则是跳出此次循环,之后还会继续下一次循环. 条件语句 ...

  5. Spring 3 MVC: Themes In Spring-Tutorial With Example---reference

    Welcome to Part 6 of Spring 3.0 MVC Series. In previous article we saw how to add Internationalizati ...

  6. [转] 在React Native中使用ART

    http://bbs.reactnative.cn/topic/306/%E5%9C%A8react-native%E4%B8%AD%E4%BD%BF%E7%94%A8art 前半个月捣腾了一下Rea ...

  7. 【转】Windows环境下.NET 操作Oracle问题

    目前,Windows操作系统可以分成两类,32位和64位(64位也区分x86_64位和Itanium ),同时Oracle客户端也做了同样的区分. 在安装和开发的过程中,经常会遇到一些问题,本文就总结 ...

  8. Web通信中的Get、Post方法

    首先我们要了解Tomcat,Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选. ...

  9. GoogleAuthenticator

    <?php /** * PHP Class for handling Google Authenticator 2-factor authentication * * @author Micha ...

  10. >=ios8 应用内跳转到系统设置界面-openURL

    iOS8以后,苹果允许从应用内跳转到系统设置,但是调试结果表明,跳不到具体的设置项,使用前应该判断当前是否能够跳转到系统设置. 代码: NSURL *url = [NSURL URLWithStrin ...