rt,目前可以确定 ISAP 写的没问题,提交记录显示都是把不可行边判成了可行边
//when you use vector or deque,pay attention to the size of it.
//by OldDirverTree
#include<bits/stdc++.h>
#define P pair<int,int>
#define int long long
#define mid (l+r>>1)
#define v to[i]
#define f val[i]
using namespace std;
const int N=4001,M=12e4;
int tot,head[N],nxt[M],to[M],val[M];
int n,m,S,T,dep[N],cur[N],gap[N];
int tim,dfn[N],low[N],bel[N];
bool ins[N]; stack<int> s;
int read() {
int x=0; char c=0; while (!isdigit(c) ) c=getchar();
while (isdigit(c) ) x=(x<<3)+(x<<1)+(c&15),c=getchar();
return x;
}
void bfs()
{
queue<int> q; q.push(T);
memset(dep,-1,sizeof dep);
gap[dep[T]=0]++;
while (!q.empty() ) {
int u=q.front(); q.pop();
for (int i=head[u];~i;i=nxt[i]) if (!~dep[v])
gap[dep[v]=dep[u]+1]++,q.push(v);
}
}
int dfs(int u,int limit)
{
if (u==T) return limit; int flow=0;
for (int i=cur[u];~i;i=nxt[i])
{
cur[u]=i;
if (f&&dep[v]+1==dep[u]) {
int t=dfs(v,min(f,limit-flow) );
flow+=t,val[i]-=t,val[i^1]+=t;
if (flow==limit) return flow;
}
}
if (!--gap[dep[u] ]) dep[S]=n;
gap[++dep[u] ]++; return flow;
}
void tarjan(int u) {
dfn[u]=low[u]=++tim,ins[u]=true,s.push(u);
for (int i=head[u];~i;i=nxt[i]) if (f) {
if (!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
else if (ins[v]) low[u]=min(low[u],dfn[v]); }
if (dfn[u]==low[u]) { ++tot; for (int x=0;x^u;x=s.top(),s.pop(),ins[x]=false,bel[x]=tot); }
}
main()
{
memset(head,-1,sizeof head);
n=read(),m=read(),S=read(),T=read();
for (int i=0;i<m;i++) {
int x=read(),y=read(),z=read();
to[tot]=y,val[tot]=z,nxt[tot]=head[x],head[x]=tot++;
to[tot]=x,val[tot]=0,nxt[tot]=head[y],head[y]=tot++;
}
bfs(); while (dep[S]<n) memcpy(cur,head,sizeof cur),dfs(S,INT_MAX);
tot=0; for (int i=1;i<=n;i++) if (!dfn[i]) tarjan(i);
for (int i=0;i<m;i++) {
if (val[i<<1]) { puts("0 0"); continue; } int x=to[i<<1|1],y=to[i<<1];
if (bel[S]==bel[x]&&bel[y]==bel[T]) puts("1 1");
else if (bel[x]^bel[y]) puts("1 0");
}
return 0;
}