https://www.luogu.org/problem/show?pid=2944

题目描述

Wisconsin has had an earthquake that has struck Farmer John's farm! The earthquake has damaged some of the pastures so that they are unpassable. Remarkably, none of the cowpaths was damaged.

As usual, the farm is modeled as a set of P (1 <= P <= 3,000)

pastures conveniently numbered 1..P which are connected by a set of C (1 <= C <= 20,000) non-directional cowpaths conveniently

numbered 1..C. Cowpath i connects pastures a_i and b_i (1 <= a_i <= P; 1 <= b_i <= P). Cowpaths might connect a_i to itself or perhaps might connect two pastures more than once. The barn is located in pasture 1.

A total of N (1 <= N <= P) cows (in different pastures) sequentially contacts Farmer John via moobile phone with an integer message report_j (2 <= report_j <= P) that indicates that pasture report_j is undamaged but that the calling cow is unable to return to the barn from pasture report_j because she could not find a path that does not go through damaged pastures.

After all the cows report in, determine the minimum number of

pastures that are damaged.

地震袭击了威斯康星州,一些牧场被摧毁了.

一共有P个牧场.由C条双向路连接.两个牧场间可能有多条路.一条路也可能连接相同的牧场.牛棚坐落在牧场1.

N (1 <= N <= P) 只奶牛打来了求救电话,说她们的农场没有被摧毁,但是已经无法到达牛棚. 求出最少可能有多少牧场被摧毁.

输入输出格式

输入格式:

  • Line 1: Three space-separated integers: P, C, and N

  • Lines 2..C+1: Line i+1 describes cowpath i with two integers: a_i and b_i

  • Lines C+2..C+N+1: Line C+1+j contains a single integer: report_j

输出格式:

  • Line 1: One number, the minimum number of damaged pastures.

输入输出样例

输入样例#1:

5 5 2
1 2
2 3
3 5
2 4
4 5
4
5
输出样例#1:

1

说明

Only pasture 2 being damaged gives such a scenario.

拆点!!!

#include<queue>
#include<cstdio>
#define N 3101
#define M 21001 using namespace std; const int inf=2e9; int n,c,p;
int src,decc,ans;
int front[N*],to[M*],nxt[M*],cap[M*],tot=;
int cnt[N*],lev[N*]; queue<int>q; void add(int u,int v,int w)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; cap[tot]=w;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; cap[tot]=;
}
bool bfs()
{
for(int i=;i<=p*+;i++)
lev[i]=-,cnt[i]=front[i];
while(!q.empty()) q.pop();
q.push(src); lev[src]=;
int now;
while(!q.empty())
{
now=q.front(); q.pop();
for(int i=cnt[now];i;i=nxt[i])
if(lev[to[i]]==- && cap[i])
{
lev[to[i]]=lev[now]+;
q.push(to[i]);
if(to[i]==decc) return true;
}
}
return false;
}
int dinic(int now,int flow)
{
if(now==decc) return flow;
int delta,rest=;
for(int &i=cnt[now];i;i=nxt[i])
{
if(cap[i] && lev[to[i]]>lev[now])
{
delta=dinic(to[i],min(flow-rest,cap[i]));
if(delta)
{
rest+=delta;
cap[i]-=delta; cap[i^]+=delta;
if(rest==flow) break;
}
}
}
if(rest!=flow) lev[now]=-;
return rest;
}
int main()
{
scanf("%d%d%d",&p,&c,&n);
decc=;
int u,v;
for(int i=;i<=p;i++) add(i<<|,i<<,);
for(int i=;i<=c;i++)
{
scanf("%d%d",&u,&v);
if(u==v) continue;
if(u==) add(v<<,,inf);
else if(v==) add(u<<,,inf);
else
{
add(u<<,v<<|,inf);
add(v<<,u<<|,inf);
}
}
for(int i=;i<=n;i++)
{
scanf("%d",&u);
add(src,u<<,inf);
}
while(bfs())
ans+=dinic(src,inf);
printf("%d",ans);
}

洛谷2944 [USACO09MAR]地震损失2Earthquake Damage 2的更多相关文章

  1. P2944 [USACO09MAR]地震损失2Earthquake Damage 2(网络流)

    P2944 [USACO09MAR]地震损失2Earthquake Damage 2 $P$个点,$C$条双向边.求最少删去几个点使$N$个给定的点与点$1$分开. 显然的最小割. 将点$i$套路地拆 ...

  2. [USACO09MAR]地震损失2Earthquake Damage 2

    地震破坏 时间限制: 1 Sec  内存限制: 128 MB 题目描述 威斯康星发生了一场地震!约翰的牧场遭到了打击,有一些牛棚变成了废墟,如果一间牛棚遭到 了破坏,那么所有和它相连的道路都不能使用了 ...

  3. p2944 [USACO09MAR]地震损失2Earthquake Damage 2

    传送门 分析 我们让s到1,关键点到t分别连流量为inf的边 于是我们可以考虑跑s到t的最小割 于是我们将所有点拆为两个点,关键点和1的两个点之间连inf,其余点连1 将原图的边也连上,流量为inf ...

  4. 洛谷P2947 [USACO09MAR]仰望Look Up

    P2947 [USACO09MAR]仰望Look Up 74通过 122提交 题目提供者洛谷OnlineJudge 标签USACO2009云端 难度普及/提高- 时空限制1s / 128MB 提交   ...

  5. 洛谷 P2932 [USACO09JAN]地震造成的破坏Earthquake Damage

    P2932 [USACO09JAN]地震造成的破坏Earthquake Damage 题目描述 Wisconsin has had an earthquake that has struck Farm ...

  6. 「洛谷P1343」地震逃生 解题报告

    P1343 地震逃生 题目描述 汶川地震发生时,四川XX中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带, ...

  7. 洛谷 P2945 [USACO09MAR]沙堡Sand Castle 题解

    题目传送门 大概思路就是把这两个数组排序.在扫描一次,判断大小,累加ans. #include<bits/stdc++.h> using namespace std; int x,y,z; ...

  8. 洛谷 P2947 [USACO09MAR]向右看齐Look Up【单调栈】

    题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again stan ...

  9. 洛谷 P2945 [USACO09MAR]沙堡Sand Castle

    传送门 题目大意: ai,ai+1,ai+2... 变成 bi,bi+1,bi+2.. 不计顺序,增加和减少a数组均有代价. 题解:贪心+排序 小的对应小的 代码: #include<iostr ...

随机推荐

  1. 软件工程 作业part1

    自我介绍 老师您好,我叫宋雨,本科在长春理工大学,专业是计算机科学与技术. 1.回想一下你曾经对计算机专业的畅想:当初你是如何做出选择计算机专业的决定?你认为过去接触的课程是否符合你对计算机专业的期待 ...

  2. iOS- <项目笔记>项目配置常见文件

    项目常见文件 1.main.m * 里面有一个程序的入口:main函数 2.Prefix.pch文件 * pch文件中的内容能被项目中的其他任何文件共享\包含\访问 * 如果定义的内容只用在OC环境中 ...

  3. Qt-排序

    1.要求传入起始指针,总长度,单元素空间占用大小(sizeof(A[i])),判断函数. 判断函数参数类型为const void *,使用需要在函数内自行转换为对应类型, 返回值为整数型,升序排序时正 ...

  4. position定位-absolute与fixed

    1. absolute 生成绝对定位元素,相对于static定位以外的第一个父元素进行定位. 2. fixed 生成绝对定位元素,相对于浏览器窗口进行定位.

  5. anaconda安装不存在的包

    Anaconda作为一个工具包集成管理工具,下载python工具包是很方便的,直接敲: conda install package_name 1 但是有时候安装一个工具包(如skimage)的时候,在 ...

  6. Android Studio类中实现Serializable自动生成serialVersionUID

    1.File -> Settings... -> Editor -> Inspections -> Serialization issues -> Serializabl ...

  7. Apache Tomcat Nginx的区别和联系

    一.定义 1. Apache Apache HTTP服务器是一个模块化的服务器,可以运行在几乎所有广泛使用的计算机平台上.其属于应用服务器.Apache支持支持模块多,性能稳定,Apache本身是静态 ...

  8. SQL局部变量

    声明局部变量 局部变量的声明需要使用declare 语句.并且必须以@开头 declare { @varaible_name datatype[,...n] } varaible_name :局部变量 ...

  9. MySQL不支持远程连接的解决办法

    如果mysql不支持远程连接,会出现提示:错误代码是1130,ERROR 1130: Host * is not allowed to connect to this MySQL server ,解决 ...

  10. POJ2115:C Looooops——题解

    http://poj.org/problem?id=2115 题目大意:for(i=A;i!=B;i+=C),i的类型的范围为0<=a<1<<k exgcd裸题目. 设a=C, ...