#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 405;
const int inf = 0x3f3f3f3f;
int n, m, s, t;
int tot, head[N], ver[N], edge[N], nxt[N];
bool vis[N];
void add(int x, int y, int z) {
ver[++tot] = y, edge[tot] = z, nxt[tot] = head[x], head[x] = tot;
ver[++tot] = x, edge[tot] = 0, nxt[tot] = head[y], head[y] = tot;
}
int dfs(int x, int flow) {
if (x == t) return flow;
vis[x] = 1;
for (int i = head[x]; i; i = nxt[i]) {
int y = ver[i], z = edge[i], c;
if (z > 0 && !vis[y]) {
c = dfs(y, min(flow, z));
if (c == -1) continue;
edge[i] -= c, edge[i ^ 1] += c;
return c;
}
}
return -1;
}
int ff() {
int ans = 0, c;
while ((c = dfs(s, inf)) != -1) {
memset(vis, 0, sizeof(vis));
ans += c;
}
return ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m >> s >> t;
for (int i = 1; i <= m; i++) {
int x, y, z; cin >> x >> y >> z;
add(x, y, z);
}
cout << ff() << endl;
return 0;
}