求赞!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=210;
queue<ll> q;
ll n,m,idx=1,ans,h[N],e[2*N],ne[2*N],w[2*N],pre[N],d[N];
bool st[N];
void add(ll u,ll v,ll c) {
e[++idx]=v,ne[idx]=h[u],w[idx]=c,h[u]=idx;
}
bool bfs() {
memset(st,0,sizeof(st));
q=queue<ll>();
st[1]=1,d[1]=9e18;
q.push(1);
while(!q.empty()) {
ll u=q.front();
q.pop();
for(ll i=h[u]; i; i=ne[i]) {
ll v=e[i];
if(!st[v] && w[i]) {
st[v]=1,pre[v]=i,d[v]=min(d[u],w[i]);
q.push(v);
if(v==m) return 1;
}
}
}
return 0;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(ll i=1,u,v,c; i<=n; ++i) cin>>u>>v>>c,add(u,v,c),add(v,u,0);
while(bfs()) {
ans+=d[m];
for(ll u=m; u!=1; u=e[pre[u]^1]) w[pre[u]]-=d[m],w[pre[u]^1]+=d[m];
}
cout<<ans;
return 0;
}