一个单源多汇的有向图,求增大那些边的容量可以使得网络的最大流增加。

很简单,直接跑最大流,保留残余网络,然后枚举所有余量为0的边,使其容量增加一个1,看看是否出现新的增广路即可。

召唤代码君:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#define maxn 555
#define maxm 55555
using namespace std; int to[maxm],c[maxm],next[maxm],first[maxn],edge;
int d[maxn],tag[maxn],TAG=;
bool can[maxn];
int Q[maxm],bot,top;
int n,m,l,s,t; void _init()
{
edge=-;
for (int i=; i<=n+m+; i++) first[i]=-;
} void addedge(int U,int V,int W)
{
edge++;
to[edge]=V,c[edge]=W,next[edge]=first[U],first[U]=edge;
edge++;
to[edge]=U,c[edge]=,next[edge]=first[V],first[V]=edge;
} bool bfs()
{
Q[bot=top=]=t,tag[t]=++TAG,d[t]=,can[t]=false;
while (bot<=top)
{
int cur=Q[bot++];
for (int i=first[cur]; i!=-; i=next[i])
if (c[i^] && tag[to[i]]!=TAG)
{
tag[to[i]]=TAG,d[to[i]]=d[cur]+;
can[to[i]]=false,Q[++top]=to[i];
if (to[i]==s) return true;
}
}
return false;
} int dfs(int cur,int num)
{
if (cur==t) return num;
int tmp=num,k;
for (int i=first[cur]; i!=-; i=next[i])
if (c[i] && d[to[i]]==d[cur]- && tag[to[i]]==TAG && !can[to[i]])
{
k=dfs(to[i],min(c[i],num));
if (k) num-=k,c[i]-=k,c[i^]+=k;
if (!num) break;
}
if (num) can[cur]=true;
return tmp-num;
} int main()
{
int U,V,W,Flow=;
vector<int> ans;
while (scanf("%d%d%d",&n,&m,&l) && (n|m|l))
{
_init();
for (int i=; i<=l; i++)
{
scanf("%d%d%d",&U,&V,&W);
addedge(V,U,W);
}
s=,t=n+m+;
for (int i=; i<=n; i++) addedge(i,t,~0U>>);
while (bfs()) Flow+=dfs(s,~0U>>);
ans.clear();
for (int i=; i<=l; i++)
{
if (c[i+i-]) continue;
c[i+i-]++;
if (bfs()) ans.push_back(i);
c[i+i-]--;
}
if (ans.size()>)
{
printf("%d",ans[]);
for (unsigned i=; i<ans.size(); i++) printf(" %d",ans[i]);
}
printf("\n");
}
return ;
}

ZOJ2532_Internship的更多相关文章

随机推荐

  1. std result_of

    #include <type_traits> auto call(const auto& f) -> typename std::result_of<decltype( ...

  2. Angular(2)

    1.自定义指令,直接栗子: note:定义指定是驼峰,2部分 前缀+作用,but  调用 改驼峰首字母大写处为 (-首字母小写) <!DOCTYPE html><html lang= ...

  3. ZeroClipboard实现复制

    今天利用ZeroClipboard实现了批量复制ip到剪贴版的公里,第一种方式总是有错,需要点击两次才能成功复制,第二种方法成功.在这里记录下,方法一: $('#copy_ips').zclip({ ...

  4. Linux ToolChain (二) --- Linker (1)链接选项 -L -rpath -rpath-link

    一.动态库的链接和链接选项-L,-rpath-link,-rpath (1). 现代连接器在处理动态库时将链接时路径(Link-time path)和运行时路径(Run-time path)分开, 用 ...

  5. eclipse与myeclipse恢复已删除的文件和代码

    1.类文件的恢复 选择项目后右键-->选择Restore from Local history-->出现下面的界面: 勾选后按Restore就恢复了,真的很强大很方便:但我没有就此罢手,我 ...

  6. java获取当前执行文件的路径

    需要知道执行jar包时,jar包所在的路径. 开始使用了 p.getClass().getResource("/").getPath(); 结果在IDE里面使用是好的,但是在命令行 ...

  7. java 动态编译

    public class Main { public static void main(String[] args) { System.out.println("Hello World!&q ...

  8. java assert

    一.语法形式: Java2在1.4中新增了一个关键字:assert.在程序开发过程中使用它创建一个断言(assertion),它的 语法形式有如下所示的两种形式: 1.assert condition ...

  9. 【转载】C++ IO库

    本篇随笔为转载,原贴地址:<C++ Primer>第8章 IO库 学习笔记. 1.IO类 #include <iostream> istream//从流中读取数据 ostrea ...

  10. 多媒体(3):基于WindowsAPI的视频捕捉卡操作

    目录 多媒体(1):MCI接口编程 多媒体(2):WAVE文件格式分析 多媒体(3):基于WindowsAPI的视频捕捉卡操作 多媒体(4):JPEG图像压缩编码 多媒体(3):基于WindowsAP ...