func_code_string: #include <bits/stdc++.h>   using namespace std;   struct node {     int from, to, next, w, dir, id;   } e[1500000];   int head[350000];   int in[350000];   int out[350000];   int ans[350000];   int n, m, cont;   void add(int from, int to, int w, int dir, int id) {     e[cont].from = from;     e[cont].to = to;     e[cont].w = w;     e[cont].dir = dir;     e[cont].id = id;     e[cont].next = head[from];     head[from] = cont++;   }   void Top() {     queue<int> s;     s.push(1);     in[1] = out[1] = 0;     while (!s.empty()) {       int u = s.front();       s.pop();       for (int i = head[u]; i != -1; i = e[i].next) {         int v = e[i].to;         int w = e[i].w;         int dir = e[i].dir;         if (v == 1 || (in[v] == out[v] && v != n)) continue;         if (u == 1 || v == n) {           if (u == 1) {             ans[e[i].id] = dir;             in[v] += w;           } else {             ans[e[i].id] = dir;           }         } else {           if (in[v] != out[v]) {             in[v] += w;             ans[e[i].id] = dir;           } else             ans[e[i].id] = 1 - dir;         }         if (in[v] == out[v] && v != n) {           s.push(v);         }       }     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);   }   int main() {     while (~scanf( %d%d , &n, &m)) {       cont = 0;       memset(in, 0, sizeof(in));       memset(out, 0, sizeof(out));       memset(head, -1, sizeof(head));       for (int i = 1; i <= m; i++) {         int x, y, w;         scanf( %d%d%d , &x, &y, &w);         add(x, y, w, 0, i);         add(y, x, w, 1, i);         out[y] += w;         out[x] += w;       }       for (int i = 1; i <= n; i++) out[i] = out[i] / 2;       Top();     }   }   