#include<bits/stdc++.h> #define MAX_N 4000 #define MAX_M 60000 #define INF 0x3f3f3f3f usingnamespace std; template <classT> inlinevoidread(T &x){ x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0'); } int n, m, s, t, cnt, d[MAX_N+5], pr[MAX_N+5], cr[MAX_N+5]; int dfn[MAX_N+5], low[MAX_N+5], col[MAX_N+5], ind, tot; structedge {int v, c, nxt;} E[MAX_M*2+5]; stack <int> sta; bool insta[MAX_N+5]; voidinit(){read(s), read(t), cnt = 0, memset(pr, -1, sizeof pr);} voidinsert(int u, int v, int c){E[cnt] = (edge){v, c, pr[u]}, pr[u] = cnt++;} voidaddedge(int u, int v, int c){insert(u, v, c), insert(v, u, 0);} boolBFS(){ queue <int> que; que.push(s); memset(d, -1, sizeof d), d[s] = 0; while (!que.empty()) { int u = que.front(); que.pop(); for (int i = pr[u]; ~i; i = E[i].nxt) { int v = E[i].v, c = E[i].c; if (~d[v] || !c) continue; d[v] = d[u]+1, que.push(v); } } return ~d[t]; } intDFS(int u, int flow){ if (u == t) return flow; int ret = 0; for (int &i = pr[u]; ~i; i = E[i].nxt) { int v = E[i].v, c = E[i].c; if (d[u]+1 != d[v] || !c) continue; int tmp = DFS(v, min(flow, c)); E[i].c -= tmp, E[i^1].c += tmp; flow -= tmp, ret += tmp; if (!flow) break; } if (!ret) d[u] = -1; return ret; } voidcpy(){for (int i = 1; i <= n; i++) cr[i] = pr[i];} voidrec(){for (int i = 1; i <= n; i++) pr[i] = cr[i];} voidDinic(){cpy(); while (BFS()) DFS(s, INF), rec();} voidtarjan(int u){ dfn[u] = low[u] = ++ind, sta.push(u), insta[u] = true; for (int i = pr[u], v; ~i; i = E[i].nxt) if (E[i].c) { if (!dfn[v = E[i].v]) tarjan(v), low[u] = min(low[u], low[v]); elseif (insta[v]) low[u] = min(low[u], dfn[v]); } if (dfn[u] == low[u]) { tot++; for (int i = sta.top(); ; i = sta.top()) { col[i] = tot, insta[i] = false; sta.pop(); if (u == i) break; } } } intmain(){ read(n), read(m), init(); for (int i = 1, u, v, c; i <= m; i++) read(u), read(v), read(c), addedge(u, v, c); Dinic(); for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan(i); s = col[s], t = col[t]; for (int i = 0; i < cnt; i += 2) { if (E[i].c) {puts("0 0"); continue;} int u = col[E[i^1].v], v = col[E[i].v]; printf("%d %d\n", (u != v), (u == s && v == t)); } return0; }