Isprime @ 2019-12-09 14:33:25
rt,Dinic死循环了 /kel
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int MAXN = 10001;
const int MAXM = 100001;
const int INF = 2147483647;
int n, m, s, t, edge_cnt = 1;
int head[MAXN];
int dep[MAXN];
bool vis[MAXN];
struct Edge {
int to, next, dis;
}edge[MAXM << 1];
inline void addedge(int from, int to, int dis) {
edge[++edge_cnt].next = head[from];
edge[edge_cnt].dis = dis;
edge[edge_cnt].to = to;
head[from] = edge_cnt;
}
inline bool bfs() {
memset(dep, 0x3f, sizeof(dep));
memset(vis, 0, sizeof(vis));
dep[s] = 0;
queue <int> q;
q.push(s);
while(!q.empty()) {
int u = q.front();
q.pop();
vis[u] = 0;
for(register int i = head[u]; i; i = edge[i].next) {
int v = edge[i].to;
if(dep[v] > dep[u] + 1 && edge[i].dis) {
dep[v] = dep[u] + 1;
if(!vis[v]) {
q.push(v);
vis[v] = 1;
}
}
}
}
if(dep[t] != 0x3f) return 1;
return 0;
}
inline int dfs(int u, int flow) {
int rlow = 0;
if(u == t) return flow;
for(register int i = head[u]; i; i = edge[i].next) {
int d = edge[i].to;
if(edge[i].dis && dep[d] == dep[u] + 1)
if(rlow = dfs(d, min(flow, edge[i].dis))) {
edge[i].dis -= rlow;
edge[i ^ 1].dis += rlow;
return rlow;
}
}
return 0;
}
inline int Dinic(int s, int t) {
int maxflow = 0, lowflow;
while(bfs()) {
while(lowflow = dfs(s, INF)) maxflow += lowflow;
}
return maxflow;
}
signed main() {
scanf("%d%d%d%d", &n, &m, &s, &t);
for(register int u, v, w, i = 1; i <= m; ++i) {
scanf("%d%d%d", &u, &v, &w);
addedge(u, v, w);
addedge(v, u, 0);
}
printf("%d\n", Dinic(s, t));
return 0;
}
by lowAltitudeFlyer @ 2020-04-04 14:16:23
Orz Isprime