[题目链接]

https://www.lydsy.com/JudgeOnline/problem.php?id=1585

[算法]

一个最小割的经典模型 , 详见代码

时间复杂度 : O(dinic(2N , 2C))

[代码]

#include<bits/stdc++.h>
using namespace std;
#define MAXN 8010
#define MAXC 50010
const int inf = 2e9; struct edge
{
int to , w , nxt;
} e[MAXC << ]; int tot , n , c , p , S , T;
int a[MAXN] , depth[MAXN], head[MAXN]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline void addedge(int u , int v , int w)
{
++tot;
e[tot] = (edge){v , w , head[u]};
head[u] = tot;
++tot;
e[tot] = (edge){u , , head[v]};
head[v] = tot;
}
inline bool bfs()
{
int l , r;
static int q[MAXN];
q[l = r = ] = S;
memset(depth , ,sizeof(depth));
depth[S] = ;
while (l <= r)
{
int cur = q[l++];
for (int i = head[cur]; i; i = e[i].nxt)
{
int v = e[i].to , w = e[i].w;
if (w > && !depth[v])
{
depth[v] = depth[cur] + ;
q[++r] = v;
if (v == T) return true;
}
}
}
return false;
}
inline int dinic(int u , int flow)
{
int rest = flow , ret = ;
if (u == T) return flow;
for (int i = head[u]; i && rest; i = e[i].nxt)
{
int v = e[i].to , w = e[i].w;
if (depth[v] == depth[u] + && w)
{
int k = dinic(v , min(rest , w));
if (!k) depth[v] = ;
e[i].w -= k;
e[i ^ ].w += k;
rest -= k;
}
}
return flow - rest;
} int main()
{ read(n); read(c); read(p);
S = * n + , T = S + ;
tot = ;
addedge(S , , inf);
for (int i = ; i <= c; i++)
{
int x , y;
read(x); read(y);
addedge(x + n , y , inf);
addedge(y + n , x , inf);
}
for (int i = ; i <= p; i++)
{
int x;
read(x);
a[x] = true;
}
addedge( , n + , inf);
for (int i = ; i <= n; i++)
{
if (a[i])
{
addedge(i , n + i , inf);
addedge(i , T , inf);
} else addedge(i , n + i , );
}
int ans = ;
while (bfs())
{
while (int flow = dinic(S , inf)) ans += flow;
}
printf("%d\n" , ans);
return ; }

[Usaco2009 MAR] Earthquake Damage 2的更多相关文章

  1. bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害

    1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害 Description Farmer John的农场里有P个牧场,有C条无向道路连接着他们,第i条道路连接着 ...

  2. 【BZOJ】1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害

    [题意]给定无向图,现在可能有一些点已经被删除,只给出信息是c个点未被删除且不能到达结点1,求最少的删除点个数. [算法]最小割 [题解]本题和1的区别是:1求的是最少的不能到达1的结点数,那么就把损 ...

  3. 【bzoj1585】[Usaco2009 Mar]Earthquake Damage 2 地震伤害 网络流最小割

    题目描述 Farmer John的农场里有P个牧场,有C条无向道路连接着他们,第i条道路连接着两个牧场Ai和Bi,注意可能有很多条道路连接着相同的Ai和Bi,并且Ai有可能和Bi相等.Farmer J ...

  4. BZOJ1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害

    n<=3000个点m<=20000条无向边的图,有p<=n个出发点,每个出发点都不可拆,现拆一些点使每个出发点都不能到达点1,求最小点数. 简单的最小割.每个点拆成两个x和y,无向边 ...

  5. bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害【最小割】

    枚举建图.jpg 一开始建的图挂了,于是枚举了几种建图方式-- 因为要删点,所以拆点,连接(i,i',1),对于原来图上的边(u,v),连接(u',v,inf),(v',u,inf),然后连接(s,i ...

  6. bzoj 3399: [Usaco2009 Mar]Sand Castle城堡

    3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MB Description 约翰用沙子建了一座城堡.正 ...

  7. BZOJ3401: [Usaco2009 Mar]Look Up 仰望

    3401: [Usaco2009 Mar]Look Up 仰望 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 87  Solved: 58[Submit ...

  8. BZOJ3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队

    3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 89  Solve ...

  9. BZOJ3399: [Usaco2009 Mar]Sand Castle城堡

    3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 22  Solved: 17[Sub ...

随机推荐

  1. POJ-3468A Simple Problem with Integers,线段数区间更新查询,代码打了无数次还是会出错~~

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K                Case Time L ...

  2. HDU 5245

    题目大意: 每次随机选择两个点,便把这两个点之间形成的子矩阵上的每一个方块涂色,问随机选择k次,整个m*n的矩阵中有多少个小方块被涂上了颜色 这道题不难,但自己智商实在捉急,一直想不出来... 因为这 ...

  3. [转]eclipse的android智能提示设置

    以往 我们往往在输入 "." 然后 alt+/ 来进行智能提示,下面这个方法,可以帮你大幅度的提高智能打开 Eclipse -> Window -> Perferenc ...

  4. 51nod1135 原根

    原根判定:$m>2$,$\varphi (m)$的不同素数是$q_1,q_2,……,q_s$,$(g,m)=1$,则$g$是$m$的一个原根的充要条件是$g^{\frac{\varphi(m)} ...

  5. msp430项目编程03

    msp430中项目---液晶12864显示 1.液晶12864工作原理 2.电路原理说明 3.代码(静态显示) 4.代码(动态显示) 5.项目总结 msp430项目编程 msp430入门学习

  6. 用Google Analytics UTM标注社会化媒体分享流量来源

    随着社会化媒体营销概念近两年的日益盛行,敢于吃螃蟹的营销工作者们展开了一些尝试,发现对社会化营销效果进行综合评估是一大难点,价值难以衡量.主要原因在于它的营销效果中混杂了直接的目标转化.品牌宣传.品牌 ...

  7. ACM-ICPC 2018 南京赛区网络预赛 L && BZOJ 2763 分层最短路

    https://nanti.jisuanke.com/t/31001 题意 可以把k条边的权值变为0,求s到t的最短路 解析  分层最短路  我们建立k+1层图 层与层之间边权为0,i 向 i+1层转 ...

  8. Java的基本运算符

    以下内容引用自http://wiki.jikexueyuan.com/project/java/basic-operators.html: Java针对操控变量提供了一组丰富的运算符.可以将所有的Ja ...

  9. ffm算法

    www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf  读书笔记 The effect of feature conjunctions(组合特征) is difficul ...

  10. SpringBoot初始教程之日志处理(二)

    SpringBoot初始教程之日志处理(二) 1.介绍 SpringBoot默认是采用logback进行日志处理.Logback是由log4j创始人设计的又一个开源日志组件.Logback是由log4 ...