OJ题号:

BZOJ3996、洛谷2936、SPOJ-MTOTALF、SCU3353

思路:

题目的要求是将所有边合并成一条边,求合并后的流量。
实际上相当于直接求最大流。
EdmondsKarp模板即可。

 #include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
const int V=,E=,s=,t=,inf=0x7fffffff;
inline int idx(const char ch) {
return (ch<='Z')?(ch-'A'):(ch-'a'+);
}
struct Edge {
int from,to,remain;
};
int sz=;
Edge e[E<<];
std::vector<int> g[V];
inline void add_edge(const int u,const int v,const int c) {
e[sz]=(Edge){u,v,c};
g[u].push_back(sz);
sz++;
}
int p[V],a[V];
inline int Augment() {
memset(a,,sizeof a);
a[s]=inf;
std::queue<int> q;
q.push(s);
while(!q.empty()) {
int x=q.front();
q.pop();
for(unsigned i=;i<g[x].size();i++) {
Edge &y=e[g[x][i]];
if(!a[y.to]&&y.remain) {
p[y.to]=g[x][i];
a[y.to]=std::min(a[x],y.remain);
q.push(y.to);
}
}
if(a[t]) break;
}
return a[t];
}
inline int EdmondsKarp() {
int maxflow=;
while(int flow=Augment()) {
for(int i=t;i!=s;i=e[p[i]].from) {
e[p[i]].remain-=flow;
e[p[i]^].remain+=flow;
}
maxflow+=flow;
}
return maxflow;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int n;
std::cin>>n;
for(int i=;i<n;i++) {
char u,v;
int c;
std::cin>>u>>v>>c;
add_edge(idx(u),idx(v),c);
add_edge(idx(v),idx(u),);
}
std::cout<<EdmondsKarp()<<std::endl;
return ;
}

[USACO09JAN]Total Flow的更多相关文章

  1. [USACO09JAN]Total Flow【网络流】

    Farmer John always wants his cows to have enough water and thus has made a map of the N (1 <= N & ...

  2. 2018.07.06 洛谷P2936 [USACO09JAN]全流Total Flow(最大流)

    P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus ...

  3. 洛谷——P2936 [USACO09JAN]全流Total Flow

    题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...

  4. AC日记——[USACO09JAN]全流Total Flow 洛谷 P2936

    题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...

  5. 洛谷 P2936 [USACO09JAN]全流Total Flow

    题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...

  6. [USACO09JAN]全流Total Flow

    题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...

  7. BZOJ3396: [Usaco2009 Jan]Total flow 水流

    3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 45  Solved: 27[Sub ...

  8. 3396: [Usaco2009 Jan]Total flow 水流

    3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 179  Solved: 73[Su ...

  9. 【luogu P2936 [USACO09JAN]全流Total Flow】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2936 菜 #include <queue> #include <cstdio> #i ...

随机推荐

  1. 出现“error LNK1169: 找到一个或多个多重定义的符号”的原因

    或许,有人真的会这样写程序吧...所以才会碰到如下哥们提出的问题. https://zhidao.baidu.com/question/131426210.html 出现这种问题的原因链接中的最佳答案 ...

  2. oracle中REGEXP_SUBSTR方法的使用

    近期在做商旅机票平台,遇到这样一个问题: 有一张tt_ticket表,用来存机票信息.里边有一个字段叫schedule,表示的是行程,存储格式为:北京/虹桥 由于公司位于上海.而上海眼下有两个机场:浦 ...

  3. web----框架基础

    Web框架本质: 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. 真实开发中的python web程序来说,一般会分为两部分:服务器 ...

  4. Python中的各种转义符\n\r\t

    转义符 描述 \ 续行符(在行尾时) \\ 反斜杠符号 ' 单引号 " 双引号 \a 响铃 \b 退格(Backspace) \e 转义 \000 空 \n 换行 \v 纵向制表符 \t 横 ...

  5. LINQ学习之旅(五)

    Union All/Union/Intersect操作和Top/Bottom操作和Paging操作和SqlMethods操作 Union All/Union/Intersect操作 适用场景:对两个集 ...

  6. 几种常见SQL分页方式效率比较

    分页很重要,面试会遇到.不妨再回顾总结一下: 一:创建测试环境,(插入100万条数据大概耗时5分钟). create database DBTestuse DBTest 二:--创建测试表 creat ...

  7. PE文件版本那些事儿

    发现文件的版本号很有意思,win7下右键属性显示两个版本号,分别是File Version 和 Product version.但使用vs编辑版本资源里面却有四处版本号,如下: 发现有以下区别,上面为 ...

  8. SpringMVC集成springfox-swagger2自动生成接口文档

    本节内容: 什么是Swaggger Springfox与Swagger的关系 SpringMVC集成springfox-swagger2 一.什么是Swaggger Swagger是一个流行的API开 ...

  9. 使用k8s operator安装和维护etcd集群

    关于Kubernetes Operator这个新生事物,可以参考下文来了解这一技术的来龙去脉: https://yq.aliyun.com/articles/685522?utm_content=g_ ...

  10. 小米note开启调试模式

    1.刷机为开发版本. 2.拨电话界面输入   *#*#717717#*#*  开启调试模式. 3.驱动好像会自己安装.