Lightwhite @ 2022-06-10 15:47:22
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
using ll = long long;
const ll kN = 1e4 + 5, kI = 1e18;
struct Edge {
ll v, nxt, cap;
} ed[kN << 7];
ll n, m, s, t, d[kN], hd[kN], nhd[kN], gap[kN], tot = 1, ans;
void add (ll u, ll v, ll c) {
ed[++tot] = {v, hd[u], c}, hd[u] = tot;
ed[++tot] = {u, hd[v], 0}, hd[v] = tot;
}
queue <ll> q;
void BFS () {
fill (d, d + n + 1, -1), d[t] = 0, gap[d[t]]++, q.push (t);
while (!q.empty ()) {
ll u = q.front (); q.pop ();
for (ll i = hd[u], v; i; i = ed[i].nxt) {
v = ed[i].v;
if (d[v] == -1) {
d[v] = d[u] + 1, gap[d[v]]++, q.push (v);
}
}
}
}
ll DFS (ll u, ll f) {
if (u == t) {
return f;
}
ll use = 0;
for (ll i = nhd[u], v; i; i = ed[i].nxt) {
nhd[u] = i, v = ed[i].v;
cerr << d[v] << ' ' << d[u] + 1 << '\n';
if (ed[i].cap && d[v] == d[u] + 1) {
ll r = DFS (u, min (ed[i].cap, f - use));
if (r) {
ed[i].cap -= r, ed[i ^ 1].cap += r, use += r;
if (use == f) {
return f;
}
}
}
}
gap[d[u]]--;
!gap[d[u]] ? d[s] = n + 1 : 0;
d[u]++, gap[d[u]]++;
return use;
}
int main () {
ios :: sync_with_stdio (false);
cin.tie (0), cout.tie (0);
cin >> n >> m >> s >> t;
for (int i = 1, u, v, c; i <= m; i++) {
cin >> u >> v >> c, add (u, v, c);
}
for (BFS (); d[s] <= n; memcpy (nhd, hd, sizeof (hd)), ans += DFS (s, kI)) {
}
cout << ans << '\n';
return 0;
}
by LiveZoom @ 2022-06-10 15:50:52
% jjz
by 红黑树 @ 2022-06-10 15:53:59
% jjz
by Aftglw @ 2022-06-10 15:54:30
39行
d[v] == d[u] + 1
改为
d[v] + 1 == d[u]
by Lightwhite @ 2022-06-10 15:57:12
@After_glow 不出意外的不对
by Lightwhite @ 2022-06-10 15:58:15
@After_glow 虽然我是倒着算dep的但是这个对有向边的判断没影响啊
by Lightwhite @ 2022-06-10 15:59:15
@红黑树 @Soba 别fAKe了
by Lightwhite @ 2022-06-10 16:01:03
@蒋金洲 因为我前面算dep的时候枚举边算的时候也是这样算的啊
by Aftglw @ 2022-06-10 16:06:53
@蒋金洲 ISAP的 bfs
是从 dfs
是从 dep
最高而 dep
最低吗
by Lightwhite @ 2022-06-10 16:10:09
@After_glow 但是,但是,确实改了没用,连0都不输出了
by Aftglw @ 2022-06-10 16:10:38
41 行 DFS
里面