import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.TreeSet;
import java.lang.Integer;
import java.util.Stack;
public class flow_kp_java {
static int nextInt() {
try {
st.nextToken();
return (int) st.nval;
return 0;
}
}
static double nextDouble() {
try {
st.nextToken();
return st.nval;
return 0;
}
}
static class Edge {
int b, c, d, i;
public Edge(int b, int c, int d, int i) {
this.b = b;
this.c = c;
this.d = d;
this.i = i;
}
}
public static void main
(String[] args
) { int n = nextInt();
int m = nextInt();
ArrayList<ArrayList<Edge>> inc = new ArrayList<ArrayList<Edge>>();
for (int i = 0; i <= n; i++) {
inc.add(new ArrayList<Edge>());
}
int[] half = new int[200001];
int[] current = new int[200001];
boolean[] visited = new boolean[200001];
int[] direction = new int[200005];
Stack<Integer> q = new Stack<Integer>();
int a, b, c;
for (int i = 0; i < m; i++) {
a = nextInt();
b = nextInt();
c = nextInt();
inc.get(a).add(new Edge(b, c, 0, i));
inc.get(b).add(new Edge(a, c, 1, i));
current[a] += c;
current[b] += c;
}
for (int i = 0; i < n; i++) {
half[i] = current[i] / 2;
}
visited[1] = true;
q.push(1);
while (!q.empty()) {
int next = q.pop();
for (Edge e : inc.get(next)) {
if (!visited[e.b]) {
direction[e.i] = e.d;
current[e.b] -= e.c;
if (current[e.b] == half[e.b] && e.b != n) {
visited[e.b] = true;
q.push(e.b);
}
}
}
}
for (int i = 0; i < m; i++) {
System.
out.
println(direction
[i
]); }
}
}
CmltcG9ydCBqYXZhLmlvLkJ1ZmZlcmVkUmVhZGVyOwppbXBvcnQgamF2YS5pby5JT0V4Y2VwdGlvbjsKaW1wb3J0IGphdmEuaW8uSW5wdXRTdHJlYW1SZWFkZXI7CmltcG9ydCBqYXZhLmlvLlN0cmVhbVRva2VuaXplcjsKaW1wb3J0IGphdmEudXRpbC5BcnJheUxpc3Q7CmltcG9ydCBqYXZhLnV0aWwuQ29sbGVjdGlvbnM7CmltcG9ydCBqYXZhLnV0aWwuSXRlcmF0b3I7CmltcG9ydCBqYXZhLnV0aWwuVHJlZVNldDsKaW1wb3J0IGphdmEubGFuZy5JbnRlZ2VyOwppbXBvcnQgamF2YS51dGlsLlN0YWNrOwoKcHVibGljIGNsYXNzIGZsb3dfa3BfamF2YSB7CgogICAgc3RhdGljIFN0cmVhbVRva2VuaXplciBzdCA9IG5ldyBTdHJlYW1Ub2tlbml6ZXIobmV3IEJ1ZmZlcmVkUmVhZGVyKG5ldyBJbnB1dFN0cmVhbVJlYWRlcihTeXN0ZW0uaW4pKSk7CgogICAgc3RhdGljIGludCBuZXh0SW50KCkgewogICAgICAgIHRyeSB7CiAgICAgICAgICAgIHN0Lm5leHRUb2tlbigpOwogICAgICAgICAgICByZXR1cm4gKGludCkgc3QubnZhbDsKICAgICAgICB9IGNhdGNoIChJT0V4Y2VwdGlvbiBleCkgewogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICB9CgogICAgc3RhdGljIGRvdWJsZSBuZXh0RG91YmxlKCkgewogICAgICAgIHRyeSB7CiAgICAgICAgICAgIHN0Lm5leHRUb2tlbigpOwogICAgICAgICAgICByZXR1cm4gc3QubnZhbDsKICAgICAgICB9IGNhdGNoIChJT0V4Y2VwdGlvbiBleCkgewogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICB9CgogICAgc3RhdGljIGNsYXNzIEVkZ2UgewoKICAgICAgICBpbnQgYiwgYywgZCwgaTsKCiAgICAgICAgcHVibGljIEVkZ2UoaW50IGIsIGludCBjLCBpbnQgZCwgaW50IGkpIHsKICAgICAgICAgICAgdGhpcy5iID0gYjsKICAgICAgICAgICAgdGhpcy5jID0gYzsKICAgICAgICAgICAgdGhpcy5kID0gZDsKICAgICAgICAgICAgdGhpcy5pID0gaTsKICAgICAgICB9CiAgICB9CgogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIGludCBuID0gbmV4dEludCgpOwogICAgICAgIGludCBtID0gbmV4dEludCgpOwoKICAgICAgICBBcnJheUxpc3Q8QXJyYXlMaXN0PEVkZ2U+PiBpbmMgPSBuZXcgQXJyYXlMaXN0PEFycmF5TGlzdDxFZGdlPj4oKTsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8PSBuOyBpKyspIHsKICAgICAgICAgICAgaW5jLmFkZChuZXcgQXJyYXlMaXN0PEVkZ2U+KCkpOwogICAgICAgIH0KCiAgICAgICAgaW50W10gaGFsZiA9IG5ldyBpbnRbMjAwMDAxXTsKICAgICAgICBpbnRbXSBjdXJyZW50ID0gbmV3IGludFsyMDAwMDFdOwogICAgICAgIGJvb2xlYW5bXSB2aXNpdGVkID0gbmV3IGJvb2xlYW5bMjAwMDAxXTsKCiAgICAgICAgaW50W10gZGlyZWN0aW9uID0gbmV3IGludFsyMDAwMDVdOwoKICAgICAgICBTdGFjazxJbnRlZ2VyPiBxID0gbmV3IFN0YWNrPEludGVnZXI+KCk7CgoKICAgICAgICBpbnQgYSwgYiwgYzsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG07IGkrKykgewogICAgICAgICAgICBhID0gbmV4dEludCgpOwogICAgICAgICAgICBiID0gbmV4dEludCgpOwogICAgICAgICAgICBjID0gbmV4dEludCgpOwogICAgICAgICAgICBpbmMuZ2V0KGEpLmFkZChuZXcgRWRnZShiLCBjLCAwLCBpKSk7CiAgICAgICAgICAgIGluYy5nZXQoYikuYWRkKG5ldyBFZGdlKGEsIGMsIDEsIGkpKTsKICAgICAgICAgICAgY3VycmVudFthXSArPSBjOwogICAgICAgICAgICBjdXJyZW50W2JdICs9IGM7CiAgICAgICAgfQogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgICAgIGhhbGZbaV0gPSBjdXJyZW50W2ldIC8gMjsKICAgICAgICB9CiAgICAgICAgdmlzaXRlZFsxXSA9IHRydWU7CiAgICAgICAgcS5wdXNoKDEpOwogICAgICAgIHdoaWxlICghcS5lbXB0eSgpKSB7CiAgICAgICAgICAgIGludCBuZXh0ID0gcS5wb3AoKTsKICAgICAgICAgICAgZm9yIChFZGdlIGUgOiBpbmMuZ2V0KG5leHQpKSB7CiAgICAgICAgICAgICAgICBpZiAoIXZpc2l0ZWRbZS5iXSkgewogICAgICAgICAgICAgICAgICAgIGRpcmVjdGlvbltlLmldID0gZS5kOwogICAgICAgICAgICAgICAgICAgIGN1cnJlbnRbZS5iXSAtPSBlLmM7CiAgICAgICAgICAgICAgICAgICAgaWYgKGN1cnJlbnRbZS5iXSA9PSBoYWxmW2UuYl0gJiYgZS5iICE9IG4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgdmlzaXRlZFtlLmJdID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgcS5wdXNoKGUuYik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbTsgaSsrKSB7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihkaXJlY3Rpb25baV0pOwogICAgICAgIH0KICAgIH0KfQo=