#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > all;
vector<pair<int, int> > edge;
vector<pair<int, int> > graph[200005];
int vis[200005], val[200005], n;
void func(void) {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      Q;
  Q.push(make_pair(0, 0));
  while (!Q.empty()) {
    pair<int, int> now = Q.top();
    Q.pop();
    if (vis[now.second]) continue;
    vis[now.second] = 1;
    for (int i = 0; i < graph[now.second].size(); i++) {
      int to = graph[now.second][i].first, w = graph[now.second][i].second;
      if (vis[to]) continue;
      all.insert(make_pair(now.second, to));
      val[to] -= (2 * w);
      if (to != n - 1) Q.push(make_pair(val[to], to));
    }
  }
  return;
}
int main() {
  int m, i;
  scanf("%d", &n);
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d", &u);
    scanf("%d", &v);
    scanf("%d", &w);
    u--;
    v--;
    val[u] += w;
    val[v] += w;
    edge.push_back(make_pair(u, v));
    graph[u].push_back(make_pair(v, w));
    graph[v].push_back(make_pair(u, w));
  }
  func();
  for (i = 0; i < m; i++) {
    if (all.find(make_pair(edge[i].first, edge[i].second)) == all.end())
      printf("1\n");
    else
      printf("0\n");
  }
  return 0;
}
