冬令营送到我脸上的20分都没拿全

心态爆炸

冬令营前一天学的dinic

后一天才发出来

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define inf 2139062143
#define ll long long
#define MAXN 1000100
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-;ch=getchar();}
while(isdigit(ch)) {x=x*+ch-'';ch=getchar();}
return x*f;
}
struct Dinic
{
int fst[MAXN],nxt[MAXN<<],to[MAXN<<],val[MAXN<<],cnt,n,m,s,t;
Dinic() {cnt=;memset(fst,0xff,sizeof(fst));}
void add(int u,int v,int w) {nxt[cnt]=fst[u],fst[u]=cnt,to[cnt]=v,val[cnt++]=w;}
int q[MAXN],dep[MAXN],cur[MAXN],vis[MAXN],tot;
int BFS()
{
int l=,r=;
memset(dep,0xff,sizeof(dep));
vis[t]=++tot,q[++r]=t;
while(l<=r)
{
int x=q[l++];cur[x]=fst[x];
for(int i=fst[x];i!=-;i=nxt[i])
{
if(val[i^]&&vis[to[i]]!=tot)
{
vis[to[i]]=tot,dep[to[i]]=dep[x]+,q[++r]=to[i];
if(to[i]==s) return ;
}
}
}
return vis[s]==tot;
}
int DFS(int x,int a)
{
if(x==t||!a) return a;
int flow=,f;
for(int& i=cur[x];i!=-;i=nxt[i])
{
if(val[i]&&dep[to[i]]==dep[x]-&&(f=DFS(to[i],min(a,val[i]))))
{
val[i]-=f,val[i^]+=f,flow+=f,a-=f;
if(!a) break;
}
}
return flow;
}
ll solve()
{
ll ans=;int f;
while(BFS())
{
memcpy(cur,fst,sizeof(cur));
while(f=DFS(s,inf)) ans+=f;
}
return ans;
}
}D;
int main()
{
int k;
D.n=read(),k=D.m=read(),D.s=read(),D.t=read();
int u,v,w;
for(int i=;i<=k;i++) {u=read(),v=read(),w=read();D.add(u,v,w);D.add(v,u,);}
printf("%lld",D.solve());
}

loj 101 最大流的更多相关文章

  1. [loj#101] 最大流 网络流模板

    #101. 最大流 内存限制:512 MiB时间限制:5000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 这是一道模板题. 给定  ...

  2. LOJ 101 最大流(ISAP 模板)

    开long long的最大流 #include<bits/stdc++.h> using namespace std; ;//点数的最大值 ;//边数的最大值 ; struct Edge ...

  3. loj#101. 最大流 dinic+当前弧

    板子题 当前弧优化版本 目前效率最高 //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize(&q ...

  4. loj 1155(最大流)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26869 思路:题目还是比较水的,由于点也有容量,则必须拆点,然后跑 ...

  5. loj 1154(最大流+枚举汇点)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26868 思路:拆点,容量为最多能跳的步数,然后设立一个超级源点,源 ...

  6. LibreOJ #101. 最大流

    题目描述 这是一道模板题. 给定 n nn 个点,m mm 条边,给定每条边的容量,求从点 s ss 到点 t tt 的最大流. 输入格式 第一行四个整数 n nn.m mm.s ss.t tt.接下 ...

  7. LibreOJ 题解汇总

    目录 #1. A + B Problem #2. Hello, World! #3. Copycat #4. Quine #7. Input Test #100. 矩阵乘法 #101. 最大流 #10 ...

  8. CTF流量分析题大全(掘安攻防平台)

    突然想做一下流量分析题,记得掘安攻防实验室上面有很多的流量分析题目,故做之 流量分析题一般使用的都是wireshark,(流量分析工具中的王牌 夺取阿富汗 说了分析http头,所以直接过滤http协议 ...

  9. 【LOJ#3097】[SNOI2019]通信(费用流)

    [LOJ#3097][SNOI2019]通信(费用流) 题面 LOJ 题解 暴力就直接连\(O(n^2)\)条边. 然后分治/主席树优化连边就行了. 抄zsy代码,zsy代码是真的短 #include ...

随机推荐

  1. JPQL 的基本使用

    一.概念 JPQL 语言,即 Java Persistence Query Language 的简称.JPQL 和 HQL 是非常类似的,支持以面向对象的方式来写 SQL 语句,当然也支持本地的 SQ ...

  2. 重置默认样式 css reset

    html { overflow-x:auto; overflow-y:scroll; } body, dl, dt, dd, ul, ol, li, pre, form, fieldset, inpu ...

  3. man中文手册安装

    转载自 https://www.cnblogs.com/fyc119/p/7116295.html man中文手册安装 下载源码 wget https://src.fedoraproject.org/ ...

  4. ubuntu tomcat自启动

    1 编写启动文件/etc/init.d/tomcat7 文件内容如下:

  5. 3.6.5 空串与Null串

        空串""是长度为0的字符串.可以调用以下代码检查一个字符串是否为空:                 String s = "greeting";    ...

  6. Java基础学习总结(85)——Java中四种线程安全的单例模式实现方式

  7. python写第一个网页

    1>安装django见别的博客http://djangobook.py3k.cn/2.0/chapter03/ 2>运行开发服务器 在命令提示符里进入目录mytest:cd: mytest ...

  8. Extended symmetrical multiprocessor architecture

    An architecture for an extended multiprocessor (XMP) computer system is provided. The XMP computer s ...

  9. Frame Stacking 拓扑排序 图论

    Description Consider the following 5 picture frames placed on an 9 x 8 array. ........ ........ .... ...

  10. 对象和变量的并发访问synchronized解析以及死锁分析排查

    一.synchronized java并发编程中存在“非线程安全"问题.“非线程安全"是指发生在多个线程对同一个对象中的实例变量并发访问时,产生的”脏读“现象,使用synchron ...