题目大意:给出一个无向图,要求删除尽量少的点,使给定的2点间不再连通,并输出字典序最小的方案
题型:图论-网络流
此题难点在于建图,后面就是套网络流的模板.
将点看成边,例如第i个点可以看成一条有向边<i*2-1,i*2>,容量为1.
如果j点和i点邻接,那么新建2条容量为无穷大的有向边<i*2,j*2-1>,<j*2,i*2-1>.
然后应用最大流最小割定理,求最大流即为第一问答案.
接着枚举删除每一个点i(即删除有向边),看最大流是否减少1,如果是则该点在最小割中,然后真的把这一点删点.
枚举完每个点之后别忘了将残量网络还原.
至于为什么要这样建图, 一时间说不清楚......

Executing...
Test 1: TEST OK [0.008 secs, 3852 KB]
Test 2: TEST OK [0.014 secs, 3852 KB]
Test 3: TEST OK [0.005 secs, 3852 KB]
Test 4: TEST OK [0.022 secs, 3852 KB]
Test 5: TEST OK [0.011 secs, 3852 KB]
Test 6: TEST OK [0.019 secs, 3852 KB]
Test 7: TEST OK [0.019 secs, 3852 KB]
Test 8: TEST OK [0.014 secs, 3852 KB]
Test 9: TEST OK [0.032 secs, 3852 KB]
Test 10: TEST OK [0.046 secs, 3852 KB]
Test 11: TEST OK [0.068 secs, 3852 KB]

All tests OK.
Your program ('telecow') produced all correct answers! This is your
submission #3 for this problem. Congratulations!

 #include <iostream>
#include <cstring>
#include <queue>
#include <stdio.h>
#define msize 210
#define INF 1000000000
using namespace std; int origin[msize][msize]={};
int r[msize][msize]={}; //残留网络,初始为原图
bool visited[msize];
int pre[msize];
int m,nVertex; //n条边,m个顶点 bool bfs(int s,int t) //寻找一条从s到t的增广路,若找到,返回true
{
int p;
queue<int> Q;
memset(pre,-,sizeof(pre));
memset(visited,false,sizeof(visited)); pre[s]=s;
visited[s]=true;
Q.push(s); while (!Q.empty())
{
p=Q.front(),Q.pop();
for (int i=; i<=nVertex; i++)
{
if (r[p][i]>&&!visited[i])
{
pre[i]=p;
visited[i]=true;
if (i==t) return true;
Q.push(i);
}
}
} return false;
} int maxFlow(int s,int t)
{
int flow=,d; while (bfs(s,t))
{
d=INF;
for (int i=t; i!=s; i=pre[i]) d=min(d,r[pre[i]][i]);
for (int i=t; i!=s; i=pre[i]) r[pre[i]][i] -= d, r[i][pre[i]] += d;
flow += d;
}
return flow;
} int main()
{
freopen("telecow.in","r",stdin);
freopen("telecow.out","w",stdout);
int s,e,c; cin>>nVertex>>m>>s>>e;
nVertex*=;
for(int i=;i<m;i++)
{
int a,b;
scanf("%d%d",&a,&b);
r[a*-][a*]=;
r[b*-][b*]=;
r[a*][b*-]=INF;
r[b*][a*-]=INF;
}
memcpy(origin,r,sizeof r);
int maxflow=maxFlow(s*,e*-);
int sum=maxflow;
memcpy(r,origin,sizeof r);
printf("%d\n",maxflow); bool first=true;
int cnt=;
for(int i=;i<=nVertex/;i++) // 模拟删掉第i个点
{
if(i==s || i==e)
continue;
if(cnt==sum)
{
break;
}
memcpy(origin,r,sizeof r);
r[i*-][i*]=; if(maxFlow(s*,e*-)+==maxflow)
{
maxflow--;
cnt++;
if(first)
{
first=false;
}
else
{
printf(" ");
}
printf("%d",i);
memcpy(r,origin,sizeof r);
r[i*-][i*]=;
}
else
{
memcpy(r,origin,sizeof r);
}
}
cout<<endl;
return ;
}

USACO5.4-TeleCowmunication的更多相关文章

  1. [Luogu1345][USACO5.4]Telecowmunication 最大流

    题目链接:https://www.luogu.org/problem/show?pid=1345 求最小割点集的大小,直接拆点转化成最小割边.把一个点拆成出点入点,入点向出点连一条容量为1的边,其他的 ...

  2. P1345 [USACO5.4]奶牛的电信Telecowmunication

    P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...

  3. 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication【最小割】分析+题解代码

    洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication[最小割]分析+题解代码 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流. ...

  4. 洛谷——P1345 [USACO5.4]奶牛的电信Telecowmunication

    P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...

  5. 题解 P1345 【[USACO5.4]奶牛的电信Telecowmunication】

    P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...

  6. AC日记——[USACO5.4]奶牛的电信Telecowmunication 洛谷 P1345

    [USACO5.4]奶牛的电信Telecowmunication 思路: 水题: 代码: #include <cstdio> #include <cstring> #inclu ...

  7. [USACO5.4]奶牛的电信Telecowmunication(网络流)

    P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...

  8. [Luogu P1345] [USACO5.4]奶牛的电信Telecowmunication (最小割)

    题面 传送门:https://www.luogu.org/problemnew/show/P1345 ] Solution 这道题,需要一个小技巧了解决. 我相信很多像我这样接蒟蒻,看到这道题,不禁兴 ...

  9. 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  10. [USACO5.4]奶牛的电信Telecowmunication

    裸的最小割,拆点时要考虑清楚到底是怎么连 如果之前i->i+n,之后又x->y+n,显然出不了解 所以可以改为i+n->i 如果要输出方案 考虑每一个一个点,如果删去这个点,最小割变 ...

随机推荐

  1. TCP/IP学习(四)TCP缓冲区大小及限制(转)

    链接来自:http://blog.csdn.net/ysu108/article/details/7764461 这个问题在前面有的部分已经涉及,这里在重新总结下.主要参考UNIX网络编程. (1)数 ...

  2. -_-#【Node】Express 400 Error: ENOENT, open

    Express 400 Error: ENOENT, open cd alleatisland, node app来启动

  3. C#程序注销、重启、关机和锁定电脑

    一:截图 二:源代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  4. qt项目转vs项目

    Qt creator是一个非常好用的跨平台项目管理工具和集成开发环境(IDE).但是对于我自己来说Visual Studio依然是我最顺手的开发工具,由于Qt使用了moc,这样要是自己管理Visual ...

  5. Servlet的一些细节(2)

    1. Servlet的创建时间 Servlet是不能单独运行,调用它的叫做Servlet引擎,或者叫做web服务器 针对客户端的多长Servlet请求,通常情况下,服务器只会创建一个Servlet实例 ...

  6. 在pcDuino上刷了AndDroid,Ubuntu,XBMC

    一.Android.Ubuntu.XBMC播放高清视频得比较 1.Andrioid上播放1080P 无压力,硬件解码 2.Ubuntu上用Mplayer播放视频会很卡,可能是没有硬解的原因 3.Ubu ...

  7. hadoop 2.0 详细配置教程(转载)

    转载: http://www.cnblogs.com/scotoma/archive/2012/09/18/2689902.html 作者:杨鑫奇 PS:文章有部分参考资料来自网上,并经过实践后写出, ...

  8. msyql 字节问题

    MySQL 数据库的varchar类型在4.1以下的版本中的最大长度限制为255,其数据范围可以是0~255或1~255(根据不同版本数据库来定).在 MySQL5.0以上的版本中,varchar数据 ...

  9. mybatis 多参数处理

    接口交互比较多, 所以 入参比较多,  有五个参数,是排序 参数, 跟这个五个参数排序,本来想写个对象的, 怕麻烦, 就把 五个参数 变成一个参数, 升序 1 ,降序2 ,比如  11221 ,第三第 ...

  10. ASP.NET DropDownList1_SelectedIndexChanged使用

    DropDownList1.AutoPostBack 属性 今天写代码给DropDownList1添加DropDownList1_SelectedIndexChanged事件,在运行测试时发现Drop ...