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

心态爆炸

冬令营前一天学的dinic

后一天才发出来

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstdlib>
  5. #include<cstring>
  6. #include<algorithm>
  7. #include<vector>
  8. #include<queue>
  9. #define inf 2139062143
  10. #define ll long long
  11. #define MAXN 1000100
  12. using namespace std;
  13. inline int read()
  14. {
  15. int x=,f=;char ch=getchar();
  16. while(!isdigit(ch)) {if(ch=='-') f=-;ch=getchar();}
  17. while(isdigit(ch)) {x=x*+ch-'';ch=getchar();}
  18. return x*f;
  19. }
  20. struct Dinic
  21. {
  22. int fst[MAXN],nxt[MAXN<<],to[MAXN<<],val[MAXN<<],cnt,n,m,s,t;
  23. Dinic() {cnt=;memset(fst,0xff,sizeof(fst));}
  24. void add(int u,int v,int w) {nxt[cnt]=fst[u],fst[u]=cnt,to[cnt]=v,val[cnt++]=w;}
  25. int q[MAXN],dep[MAXN],cur[MAXN],vis[MAXN],tot;
  26. int BFS()
  27. {
  28. int l=,r=;
  29. memset(dep,0xff,sizeof(dep));
  30. vis[t]=++tot,q[++r]=t;
  31. while(l<=r)
  32. {
  33. int x=q[l++];cur[x]=fst[x];
  34. for(int i=fst[x];i!=-;i=nxt[i])
  35. {
  36. if(val[i^]&&vis[to[i]]!=tot)
  37. {
  38. vis[to[i]]=tot,dep[to[i]]=dep[x]+,q[++r]=to[i];
  39. if(to[i]==s) return ;
  40. }
  41. }
  42. }
  43. return vis[s]==tot;
  44. }
  45. int DFS(int x,int a)
  46. {
  47. if(x==t||!a) return a;
  48. int flow=,f;
  49. for(int& i=cur[x];i!=-;i=nxt[i])
  50. {
  51. if(val[i]&&dep[to[i]]==dep[x]-&&(f=DFS(to[i],min(a,val[i]))))
  52. {
  53. val[i]-=f,val[i^]+=f,flow+=f,a-=f;
  54. if(!a) break;
  55. }
  56. }
  57. return flow;
  58. }
  59. ll solve()
  60. {
  61. ll ans=;int f;
  62. while(BFS())
  63. {
  64. memcpy(cur,fst,sizeof(cur));
  65. while(f=DFS(s,inf)) ans+=f;
  66. }
  67. return ans;
  68. }
  69. }D;
  70. int main()
  71. {
  72. int k;
  73. D.n=read(),k=D.m=read(),D.s=read(),D.t=read();
  74. int u,v,w;
  75. for(int i=;i<=k;i++) {u=read(),v=read(),w=read();D.add(u,v,w);D.add(v,u,);}
  76. printf("%lld",D.solve());
  77. }

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. TWaver3D特效之高光反射

    前篇我们介绍了TWaver 3D的环境映射特效,下面我们接着给大家分享高光反射特效.高光反射定义了物体上的某一区域比其他地方更反光.在高光反射的贴图中,黑色区域的反射率为0(完全不反光),白色区域的反 ...

  2. [USACO] 奶牛混合起来 Mixed Up Cows

    题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i & ...

  3. MySQL数据导入sql文件过程中出错

    错误类型: ERROR 1231 (42000): Variable 'time_zone' can't be set to the value of 'NULL' ERROR 1231 (42000 ...

  4. Linux查看Port状态命令、密钥SSH、会话同步

    查看Port状态 ss -ntl命令,参数: 参数 作用 -a 显示所有的套接字 -l 显示所有连接状态的套接字 -e 显示详细的套接字信息 -m 显示套接字的内存使用情况 -p 显示套接字的进程信息 ...

  5. Python学习第二阶段Day2(json/pickle)、 shelve、xml、PyYAML、configparser、hashlib模块

    1.json/pickle   略. 2.shelve模块 import shelve # shelve 以key value的形式序列化,value为对象 class Foo(object): de ...

  6. hdu 1754 I Hate It(线段树水题)

    >>点击进入原题测试<< 思路:线段树水题,可以手敲 #include<string> #include<iostream> #include<a ...

  7. 学习MongoDB--(5-2):索引(查看索引的使用,管理索引)

    前一篇简单介绍了索引,并给出了基本的索引使用,这一次,我们进一步说一下MongoDB中的索引,包括如何查看查询是否走索引,如何管理索引和地理空间索引等. [使用explain和hint] 前面讲高级查 ...

  8. hdu 2604 矩阵快速幂模板题

    /* 矩阵快速幂: 第n个人如果是m,有f(n-1)种合法结果 第n个人如果是f,对于第n-1和n-2个人有四种ff,fm,mf,mm其中合法的只有fm和mm 对于ffm第n-3个人只能是m那么有f( ...

  9. Docker Command

    1. #docker inspect id           这个命令给出和容器相关的所有信息(https://www.imooc.com/video/15730) 2. #docker searc ...

  10. 学PHP也要懂得HTML

    简单的HTML制做: html超文本标记语言 HTML文件主体结构: <!DOCTYPE html><html> <!--htlm开始标记 --><head& ...