liqiqi @ 2019-09-03 16:58:24
#include <bits/stdc++.h>//Dinic最大流
using namespace std;
struct edge {
int to, cap, rev;
};
vector<edge> g[100000];
int l[100000];
int it[100000];
int n, m, s, t;
void bfs(int x)
{
memset(l, -1, sizeof(l));
queue<int> q;
l[x] = 0;
q.push(x);
while (q.size())
{
int v = q.front();
q.pop();
for (int i = 0; i < g[v].size(); i++)
{
edge e = g[v][i];
if (e.cap > 0 && l[e.to] < 0)
{
l[e.to] = l[v] + 1;
q.push(e.to);
}
}
}
}
int dfs(int v, int w, int f)
{
if (v == w)
return f;
for (int i = it[v]; i < g[v].size(); i++)
{
edge &e= g[v][i];
if (e.cap > 0 && l[v] < l[e.to])
{
int d = dfs(e.to, t, min(f, e.cap));
if (d > 0)
{
e.cap -= d;
g[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
int flow(int x, int y)
{
int flow = 0;
while (1)
{
bfs(x);
if (l[y] < 0)
return flow;
memset(it, 0, sizeof(it));
int f=0;
while ((f = dfs(x, y, 1e7)) > 0)
flow += f;
}
}
int main()
{
cin >> n >> m >> s >> t;
while (m--)
{
int qq, ww, ee;
cin >> qq >> ww >> ee;
g[qq].push_back({ ww, ee, (int)g[ww].size() });
g[ww].push_back({ qq, 0, (int)g[qq].size()-1});
}
cout << flow(s, t);
}
by Dorbmon @ 2019-09-03 16:59:37
%%%%%%本蒟蒻没见过这种用法
by liqiqi @ 2019-09-03 17:02:06
@Dorbmon 白书里面这样写的,看不懂&的意思
by Dorbmon @ 2019-09-03 17:06:58
@liqiqi 啥白书?
by JT_kk @ 2019-09-03 17:07:07
@liqiqi 表示引用,对 e 进行修改相当于直接对 g[u][i]进行修改
by ud2_ @ 2019-09-03 17:08:07
&
表示引用:对 e
的修改就是对 g[v][i]
的修改。
by liqiqi @ 2019-09-03 17:09:06
@JT_kk 好的,谢谢了
by liqiqi @ 2019-09-03 17:09:22
@sjx233 好的,谢谢了
by liqiqi @ 2019-09-03 17:10:01
@Dorbmon 挑战程序设计竞赛。。
by Dorbmon @ 2019-09-03 17:17:20
@liqiqi ..没看过2333%%%%%%