码迷,mamicode.com
首页 > 其他好文 > 详细

刘汝佳dicnic模板

时间:2018-09-22 14:37:35      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:nic   ios   bre   cto   begin   tor   isp   pac   front   

技术分享图片
  1 #include<iostream>
  2 #include<cstdio>
  3 #include<algorithm>
  4 #include<vector>
  5 #include<queue>
  6 #include<cstring>
  7 #define mp make_pair
  8 #define pb push_back
  9 #define first fi
 10 #define second se
 11 #define pw(x) (1ll << (x))
 12 #define sz(x) ((int)(x).size())
 13 #define all(x) (x).begin(),(x).end()
 14 #define rep(i,l,r) for(int i=(l);i<(r);i++)
 15 #define per(i,r,l) for(int i=(r);i>=(l);i--)
 16 #define FOR(i,l,r) for(int i=(l);i<=(r);i++)
 17 #define eps 1e-9
 18 #define PIE acos(-1)
 19 #define cl(a,b) memset(a,b,sizeof(a))
 20 #define fastio ios::sync_with_stdio(false);cin.tie(0);
 21 #define lson l , mid , ls
 22 #define rson mid + 1 , r , rs
 23 #define ls (rt<<1)
 24 #define rs (ls|1)
 25 #define INF 0x3f3f3f3f
 26 #define LINF 0x3f3f3f3f3f3f3f3f
 27 #define freopen freopen("in.txt","r",stdin);
 28 #define cfin ifstream cin("in.txt");
 29 #define lowbit(x) (x&(-x))
 30 #define sqr(a) a*a
 31 #define ll long long
 32 #define ull unsigned long long
 33 #define vi vector<int>
 34 #define pii pair<int, int>
 35 #define dd(x) cout << #x << " = " << (x) << ", "
 36 #define de(x) cout << #x << " = " << (x) << "\n"
 37 #define endl "\n"
 38 using namespace std;
 39 //**********************************
 40 struct Edge{
 41     int from,to,cap,flow;
 42 }edge;
 43 void addedge(int from,int to,int cap)
 44 {
 45     edge.pb((Edge){from,to,cap,0});
 46     edge.pb((Edge){to,from,0,0});
 47     m=sz(edge);
 48     G[from].pb(m-2);G[to].pb(m-1);
 49 }
 50 struct Dinic{
 51     int n,m,s,t;
 52     vector<Edge>edge;
 53     vi G[maxn];
 54     int d[maxn];
 55     int cur[maxn];
 56     bool bfs()
 57     {
 58         cl(vis,0);
 59         queue<int>Q;
 60         d[s]=0;vis[s]=1;Q.push(s);
 61         while(!Q.empty()){
 62             int x=Q.front();Q.pop();
 63             rep(i,0,sz(G[x])){
 64                 if(!vis[e.to]&&e.cap>e.flow){
 65                     vis[e.to]=1;
 66                     d[e.to]=d[x]+1;
 67                     Q.push(e.to);
 68                 }
 69             }
 70         }
 71         return vis[t];
 72     }
 73     int dfs(int x,int a)
 74     {
 75         if(x==t||a==0)return a;
 76         int flow=0,f;
 77         rep(i,cur[x],sz(G[x])){
 78             cur[x]=i;
 79             Edge& e=edge[G[x][i]];
 80             if(d[x]+1==d[e.to]&&(f=dfs(e.to,min(a,e.cap-e.flow)))>0){
 81                 e.flow+=f;
 82                 edge[G[x][i]^1].flow-=f;
 83                 flow+=;
 84                 a-=f;
 85                 if(a==0)break;
 86             }
 87         }
 88         return flow;
 89     }
 90     int Maxflow(int s,int t)
 91     {
 92         this->s=s;this->t=t;
 93         int flow=0;
 94         while(bfs()){
 95             cl(cur,0);
 96             flow+=dfs(s,INF);
 97         }
 98         return flow;
 99     }
100 }; 
101 //**********************************
102 
103 //**********************************
104 int main()
105 {
106 
107 
108     return 0;
109 }
View Code

 

刘汝佳dicnic模板

标签:nic   ios   bre   cto   begin   tor   isp   pac   front   

原文地址:https://www.cnblogs.com/klaycf/p/9689755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!