/***********************************************\
|Author: YMC
|Created Time: 2014/4/15 19:00:30
|File Name: 1.cpp
|Description:
\***********************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#define MAX_V 1005
#define INF 0x7fffffff
using namespace std;
struct edge{
int to,cap,rev;//终点,容量,反向边
};
vector <edge> G[MAX_V];
bool used[MAX_V];
void add_edge(int from,int to,int cap){
G[from].push_back((edge){to,cap,G[to].size()});
G[to].push_back((edge){from,0,G[from].size()-1});
}
int dfs(int v,int t,int f){ //寻找增广边
if(v == t) return f;
used[v] = true;
for(int i=0;i<G[v].size();++i){
edge &e = G[v][i];
if(!used[e.to] && e.cap > 0){
int d = dfs(e.to,t,min(f,e.cap));
if(d > 0){
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
int max_flow(int s,int t){
int flow = 0;
for(;;){
memset(used,0,sizeof(used));
int f = dfs(s,t,INF);
if(f == 0) return flow;
flow += f;
}
}
int main() {
//freopen("input.txt","r",stdin);
int n;
scanf("%d",&n);
int from,to,cap;
int s,t;
while(n--){
scanf("%d%d%d",&from,&to,&cap);
add_edge(from,to,cap);
}
scanf("%d%d",&s,&t);
printf("%d\n",max_flow(s,t));
return 0;
}
/*
7
4 1 10
1 3 6
1 2 6
3 2 3
4 2 2
2 5 5
3 5 8
4 5
11
请按任意键继续. . .
*/