#include #include #include #include #include #include #include #include using namespace std; #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() typedef long long ll; const int N = 110, M = N*(N-1); const ll INF = 1e18; int n, m; int cap[2*M]; int dest[2*M]; int link[2*M]; int head[N]; int last[N]; int cnt = 0; int s, t; void add_arc(int i, int j, int c) { cap[cnt] = c; dest[cnt] = j; link[cnt] = -1; if(head[i] == -1) head[i] = cnt; else { int arc = last[i]; link[arc] = cnt; } last[i] = cnt; cnt++; cap[cnt] = 0; dest[cnt] = i; link[cnt] = -1; if(head[j] == -1) head[j] = cnt; else { int arc = last[j]; link[arc] = cnt; } last[j] = cnt; cnt++; } int level[N]; int q[N]; bool bfs() { int qh = 0, qt = 0; fill(level, level + N, -1); level[s] = 0; q[qt++] = s; while(qt > qh) { int v = q[qh++]; for(int arc = head[v]; arc != -1; arc = link[arc]) { int u = dest[arc], c = cap[arc]; if(level[u] == -1 && c > 0) { q[qt++] = u; level[u] = level[v] + 1; } } } return level[t] != -1; } inline ll dfs(int v = s, ll flow = INF) { if(!flow) return 0LL; if(v == t) return flow; for(int arc = head[v]; arc != -1; arc = link[arc]) { int u = dest[arc], c = cap[arc]; if(level[u] == level[v] + 1) { ll pushed = dfs(u, min(flow, (ll)c)); if(pushed) { cap[arc] -= pushed; cap[arc^1] += pushed; return pushed; } } } return 0; } void init() { fill(head, head + N, -1); } int main() { ios_base::sync_with_stdio(false); // freopen("in.txt", "r", stdin); init(); cin >>n >>m; s = 0, t = n - 1; for(int i = 0; i < m; i++) { int a, b, c; cin >>a >>b >>c; a--, b--; add_arc(a, b, c); add_arc(b, a, c); } ll pushed = 0; while(bfs()) { pushed += dfs(); } cout <