#include <iostream>
#include <vector>

using namespace std;

const int maxn = 100; // agar tewdad yal ha km bashad ta 300 niz javab midahad
int n, m, s, t, excess[maxn], flow[maxn][maxn], capacity[maxn][maxn], h[maxn];
vector<int> G[maxn];

void push(int u, int v){
    int amount = min(excess[u] , capacity[u][v]-flow[u][v]);
    excess[u] -= amount;
    excess[v] += amount;
    flow[u][v] += amount;
    flow[v][u] -= amount;
}

void relabel(int u){
    int newheight = 2*n-1;
    for(int v=0; v<n; v++){
        if (capacity[v] - flow[v] > 0) newheight = min(newheight, h[v]+1);
    }
    h[u] = newheight;
}

int main(){
    cin >> n >> m >> s >> t;
    s--, t--;
    for(int i=0; i<m;i ++){
        int u, v, cap;
        cin >> u >> v >> cap;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
        capacity[u][v] = cap;
    }
    
    for(int i=0; i<n; i ++){
        excess[s] = capacity[s][i]; // az anja ke hame push mishavand excess in raws 0 mimanad
        push(s,i);
    }
    h[s] = n;
    
    bool cntinue = true;
    while(cntinue){
        bool next = false;
        for(int u=0; u<n; u++){
            if(u==s || u==t) continue;
            if(excess[u] > 0){
                next = true;
                for(int i=0; i<G[u].size(); i++){
                    int v=G[u][i];
                    if(h[u] > h[v]) push(u,v) ; // agar available nabashad hichi push nemishavad
                }
                if(excess[u] > 0) relabel(u); // agar excess hanooz mosbat bood digar pushi nadarim
            }
        }
        cntinue = next;
    }
    
    cout << excess[t] << endl; // dar in ja excess[t] andaze shar bishine ast zira hich gah t ra push nemikonim
    return 0;
}