Pagini recente » Cod sursa (job #2108367) | Cod sursa (job #359869) | Cod sursa (job #1005898) | Cod sursa (job #806844) | Cod sursa (job #2204552)
#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 1e3, kMaxM = 5e3;
struct Edge {
int x, y, c, f;
int Other(int node) const { return x ^ y ^ node; }
int Capacity(int node) const { return (node == x) ? c - f : f; }
void Push(int node) { f += ((node == x) << 1) - 1; }
};
Edge e[kMaxM];
vector<int> graph[kMaxN];
bool vis[kMaxN];
int n;
bool Df(int node) {
if (node == n - 1) return true;
vis[node] = true;
for (auto eidx : graph[node]) {
auto&& e = ::e[eidx];
if (not vis[e.Other(node)]
and e.Capacity(node) != 0
and Df(e.Other(node))) {
e.Push(node);
return true;
}
}
return false;
}
int main() {
#ifdef INFOARENA
freopen("maxflow.in", "r", stdin);
freopen("maxflow.out", "w", stdout);
#endif
int m; cin >> n >> m;
for (int i = 0; i < m; ++i) {
int x, y, c; cin >> x >> y >> c; --x; --y;
e[i] = {x, y, c, 0};
graph[x].push_back(i);
graph[y].push_back(i);
}
int fl = 0;
while (Df(0)) {
memset(vis, 0, n);
++fl;
}
cout << fl << endl;
}