题面

UPD:COGS 貌似进不去了,链接失效就删掉了。

如果你不小心看到了题目评论区,那你就会知道这是一道双倍经验题,另一题的链接见题目评论区……

网络流+tarjan好题,但如果你真的的理解了网络流反向边的作用,那这就是一道大水题……

题目要求出一定在最大流中的边的数目,显然先跑网络流(废话),然后考虑到题目要求的是一定在最大流中的边,换就话说,这条边要不可替代,什么边不可替代呢——割边(大雾)连接着两个强连通分量的边。

为什么呢?

首先,我们要知道边满流的概念。对于正向边(并没有找到标准说法,若有知道的,评论告知),当且仅当他的流量等于容量(废话),在这道题中,就是一条匹配边(容量为一);对于反向边,当且仅当他对应的正向边流量为零,在这道题中,就是一条未匹配边的反向边。(也许和标准定义不一样,就先这么理解这道题吧)

若一条边在某个强连通分量中,则这条边连接的两个点X—>Y,一定存在一条路径Y—>X,且这条路径上的边全部都是反向边,故原图中必然存在一条路径从X—>Y,且路径上的边全部都是未匹配边,即这条边不是不可替代的。

于是,我们就可以在满流的边上跑tarjan,然后枚举每一条满流的判断即可。

 #include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <complex>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define rg register
#define ll long long
using namespace std; inline int gi()
{
rg int r = ; rg bool b = ; rg char c = getchar();
while ((c < '' || c > '') && c != '-') c = getchar();
if (c == '-') b = ;
while (c >= '' && c <= '') { r = (r << ) + (r << ) + c - '', c = getchar(); }
if (b) return r; return -r;
} const int inf = , N = 1e5+, M = 6e5+;
int n,m,w,S,T,Time,num,mac[N],pre[N],f[N];
int stc[N],scc[N],dep[N],dfn[N],low[N];
queue <int> q;
struct Edge
{
int to,nx,cap;
}eg[M]; inline void add(int x,int y,int z)
{
eg[++num]=(Edge){y,f[x],z}; f[x]=num;
} inline int dfs(int o,int flow)
{
if (!flow || o == T)
return flow;
int i,to,cap,tmp,fl;
fl=;
for (i=f[o]; i; i=eg[i].nx)
{
to=eg[i].to, cap=eg[i].cap;
if (dep[to] != dep[o]+ || cap <= )
continue;
tmp=dfs(to,min(flow,cap));
eg[i].cap-=tmp, eg[i^].cap+=tmp;
fl+=tmp, flow-=tmp;
if (!flow)
break;
}
if (!fl)
dep[o]=;
return fl;
} inline int bfs()
{
int i,o,to,cap;
memset(dep,,sizeof(dep));
q.push(S), dep[S]=;
while (!q.empty())
{
o=q.front(), q.pop();
for (i=f[o]; i; i=eg[i].nx)
{
to=eg[i].to, cap=eg[i].cap;
if (dep[to] || cap <= )
continue;
dep[to]=dep[o]+;
if (to == T)
{
while (!q.empty()) q.pop();
break;
}
q.push(to);
}
}
return dep[T];
} inline int dinic()
{
int flow;
flow=;
while (bfs())
flow+=dfs(S,inf);
return flow;
} inline void tarjan(int o)
{
int i,to,cap;
dfn[o]=low[o]=++Time;
stc[++stc[]]=o;
for (i=f[o]; i; i=eg[i].nx)
{
to=eg[i].to, cap=eg[i].cap;
if (cap > )
continue;
if (!dfn[to])
{
tarjan(to);
low[o]=min(low[to],low[o]);
}
else if (!scc[to])
low[o]=min(low[o],dfn[to]);
}
if (low[o] == dfn[o])
{
++scc[T+];
do
{
to=stc[stc[]--];
scc[to]=scc[T+];
}
while (to != o);
}
} int main()
{
freopen("sphere.in","r",stdin);
freopen("sphere.out","w",stdout);
int i,x,y,ans,cap;
n=gi(), m=gi();
S=, T=n+, num=, ans=, n>>=;
for (i=; i<=m; i++)
{
x=gi(), y=gi();
add(x,y,), add(y,x,);
}
for (i=; i<=n; ++i)
{
add(S,i,), add(i,S,);
add(i+n,T,), add(T,i+n,);
}
w=dinic();
for (i=S; i<=T; ++i)
if (!dfn[i])
tarjan(i);
m<<=, m++;
for (i=; i<=m; i+=)
{
cap=eg[i].cap, x=eg[i].to, y=eg[i^].to;
if (cap > )
continue;
if (scc[x] != scc[y])
ans++;
}
printf("%d\n",ans);
return ;
}

COGS【345】共荣圈 && 【426】血帆海盗的更多相关文章

  1. [补档][COGS 426]血帆海盗

    [COGS 426]血帆海盗 题目 传送门:http://cogs.pro/cogs/problem/problem.php?pid=426 随着资本的扩大,藏宝海湾贸易亲王在卡利姆多和东部王国大陆各 ...

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. 【COGS 254】【POI 2001】交通网络图

    http://www.cogs.top/cogs/problem/problem.php?pid=254 dist[i]表示能最早到达i点的时间.这样就可以用最短路模型来转移了. #include&l ...

  4. 【COGS】894. 追查坏牛奶

    http://cojs.tk/cogs/problem/problem.php?pid=894 题意:n个点m条边的加权网络,求最少边数的按编号字典序最小的最小割.(n<=32, m<=1 ...

  5. 【COGS】147. [USACO Jan08] 架设电话线(二分+spfa)

    http://cojs.tk/cogs/problem/problem.php?pid=147 学到新姿势了orz 这题求的是一条1-n的路径的最大路径最小. 当然是在k以外的. 我们可以转换一下. ...

  6. 【COGS & USACO Training】710. 命名那个数字(hash+水题+dfs)

    http://cojs.tk/cogs/problem/problem.php?pid=710 近日开始刷水... 此题我为了练一下hash...但是hash跑得比暴力还慢.. 不言而喻... #in ...

  7. 【COGS & USACO】896. 圈奶牛(凸包)

    http://cojs.tk/cogs/problem/problem.php?pid=896 我的计算几何入门题... 看了看白书的计算几何部分,,恩好嘛.. 乃们都用向量!!!! 干嘛非要将2个点 ...

  8. 【COGS】714. USACO 1.3.2混合牛奶(贪心+水题)

    http://cojs.tk/cogs/problem/problem.php?pid=714 在hzwer的刷题记录上,默默地先跳过2题T_T...求凸包和期望的..T_T那是个啥..得好好学习 看 ...

  9. Cogs 97. [NOIP2007] 树网的核 Floyd

    题目: http://cojs.tk/cogs/problem/problem.php?pid=97 97. [NOIP2007] 树网的核 ★☆   输入文件:core.in   输出文件:core ...

随机推荐

  1. fastscript增加三方控件之二

    fastscript增加三方控件之二 unit fs_BsDataSet; interface {$i fs.inc} uses SysUtils, Classes, fs_iinterpreter, ...

  2. iOS- Exception Type: 00000020:什么是看门狗机制(转)

    1.前言    前几天我们项目闪退之后遇到的一个Crash,之后逛了许多论坛,博客都没有找到满意的回复  在自己做了深入的研究之后,对iOS的看门狗机制有了一个基本的了解  而有很多奇怪的Crash可 ...

  3. sublime的tab和spaces空格切换的坑

    python是严格要求对齐或者叫缩进的: 使用sublime对python进行编程时,可以使用tab或者空格,但是不能混用.特别是从外面把代码拷贝进sublime的时候,更要注意是否一致. 简单介绍一 ...

  4. 一起talk C栗子吧(第八十四回:C语言实例--使用信号进行进程间通信一)

    各位看官们,大家好,上一回中咱们说的是进程间通信的样例.这一回咱们说的样例是:使用信号进行进程间通信.闲话休提,言归正转. 让我们一起talk C栗子吧! 我们在上一回中提到过进程之间通信须要解决的三 ...

  5. ThinkPHP学习(五)图片验证码

    今天用到图片验证码的功能,在网上找到ThinkPHP的下面代码: Public function verify(){ import('think.Image'); Image::buildImageV ...

  6. Odoo POS

    Jeffery Q:913547235     Odoo 8 只支持 ean13条码 Barcode scanner相当于键盘,30ms 条码枪输出类型,QWERTY     pos配置       ...

  7. 分享ArcGIS Server 10.0修复安装心得

    最近,捣腾了一阵子在xp系统上安装ArcGIS Server10.0(下方均简称server),解决了一些初学者可能面临的problem,给大家贴出来, 希望能够给初学者一些有益的帮助. 我的系统环境 ...

  8. c语言-完全背包问题

    完全背包问题 问题:有N种物品和一个容量为V的背包,每种物品都有无限件可用.第i种物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大. 分 ...

  9. ORACLE 11G 单实例 磁盘文件系统 DG 归档日志删除脚本 基于RED HAT LINUX 5.3 X86 64BIT

    近期做个DG的归档日志删除, [oracle@.local logs]crontab -l * 8 * * * sh /home/oracle/dbscripts/del_arc.sh 该脚本分别调用 ...

  10. MVC3-表单

    [.NET Core已取消]Html.BeginForm() 该方法用于构建一个From表单的开始,他的构造方法为:Html.BeginForm("ActionName", &qu ...