#include <bits/stdc++.h> using namespace std; inline int read(){ int rtn=0,f=1;char ch=getchar(); for(;!isdigit(ch);ch=getchar())if(ch=='-')f=0; for(;isdigit(ch);ch=getchar())rtn=(rtn<<1)+(rtn<<3)+ch-'0'; return f?rtn:-rtn; } const int maxn=200010; const int inf=1e9; int n,m,v,u,w,cnt=1; struct edge{ int a,b,w; }E[maxn]; struct node{ int a,b,c,nt; }e[maxn<<3]; struct Graph{ int p[maxn>>2],dep[maxn>>2]; inline void add(int x,int y,int z){ e[++cnt].a=x,e[cnt].b=y,e[cnt].c=z; e[cnt].nt=p[x];p[x]=cnt; e[++cnt].a=y,e[cnt].b=x,e[cnt].c=w; e[cnt].nt=p[y];p[y]=cnt; } inline bool bfs(int s,int t){ queue<int>q; memset(dep,0,sizeof(dep)); dep[s]=1;q.push(s); while(q.size()){ int k=q.front();q.pop(); for(int i=p[k];i;i=e[i].nt){ int kk=e[i].b; if(dep[kk]||!e[i].c)continue; dep[kk]=dep[k]+1; if(!dep[t])q.push(kk); } }return dep[t]; } inline int dfs(int k,int t,int flow){ if(k==t||!flow)return flow; int rtn=0; for(int i=p[k];i&&flow;i=e[i].nt){ int kk=e[i].b; if(dep[kk]!=dep[k]+1||!e[i].c)continue; int a=dfs(kk,t,min(e[i].c,flow)); flow-=a;rtn+=a; e[i].c-=a;e[i^1].c+=a; } if(!rtn)dep[k]=0; return rtn; } inline int Dinic(int s,int t){ int rtn=0; while(bfs(s,t)) rtn+=dfs(s,t,inf); return rtn; } inline void clear(){ for(int i=1;i<=n;i++)p[i]=0; cnt=1; } }G; int main(){ n=read(),m=read(); for(int i=1;i<=m;i++)E[i].a=read(),E[i].b=read(),E[i].w=read(); v=read();u=read();w=read(); for(int i=1;i<=m;i++) if(E[i].w<w) G.add(E[i].a,E[i].b,1); int ans=G.Dinic(v,u); G.clear(); for(int i=1;i<=m;i++) if(E[i].w>w) G.add(E[i].a,E[i].b,1); ans+=G.Dinic(v,u); printf("%d\n",ans); return 0; }
|