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. 物联网常见通信协议RFID、NFC、Bluetooth、ZigBee等梳理

    1  概述 在上一篇文章<物联网常见通信协议与通讯协议梳理[上]-通讯协议>中,对物联网常用通信协议和通讯协议作了区分,并对通讯协议进行了分享:本文将对常用的通信协议进行剖析,重点面向市场 ...

  2. JAVA单态设计模式

    核心--在类的内部把构造器私有化,同时在内部产生对象,并通过类.静态方法(static)返回实例化对象的引用   设计模式是在大量的实践总结和理论化之后优选的代码结果,编程风格,以及解决问题的思考方式 ...

  3. ACM 第四天

    A - 最短路 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的 ...

  4. lintcode-149-买卖股票的最佳时机

    149-买卖股票的最佳时机 假设有一个数组,它的第i个元素是一支给定的股票在第i天的价格.如果你最多只允许完成一次交易(例如,一次买卖股票),设计一个算法来找出最大利润. 样例 给出一个数组样例 [3 ...

  5. Python 元组 集合

    1. 元组 >>> a = (1,2,3,4,5) >>> b = list(a) #转换成列表对象, 可以更改 >>> b [1, 2, 3, ...

  6. OSG配置捷径,VS2013+WIN10

    在自己电脑上用CMAKE已经编译好了,上传到百度云里面了. 环境是WIN10+VS2013. 链接:http://pan.baidu.com/s/1hrO7GFE 密码:fwkw 解压之后放在C盘或者 ...

  7. PAT L2-028 秀恩爱分得快

    https://pintia.cn/problem-sets/994805046380707840/problems/994805054698012672 古人云:秀恩爱,分得快. 互联网上每天都有大 ...

  8. adb shell input keyevent值所对应的字符

    转自:http://blog.csdn.net/chen825919148/article/details/18732041 0 -->  "KEYCODE_UNKNOWN" ...

  9. c运行时库,c标准库,Windows系统api的关系

    原文地址:http://blog.csdn.net/seastars_sh/article/details/8233324 C运行库和C标准库的关系 C标准库,顾名思义既然是标准,就是由标准组织制定的 ...

  10. filter过滤器 默认情况下只对客户端发来的请求有过滤作用 对服务端的跳转不起作用 需要显示的在xml定义过滤的方式才行

    filter过滤器 默认情况下只对客户端发来的请求有过滤作用 对服务端的跳转不起作用 需要显示的在xml定义过滤的方式才行