The obtained directed graph does not have cycles. InputThe first line of input contains two space-separated integersNAndM(2? ¡U?N? ¡U? 2 Tib limit 105,N? -? 1? ¡U?M? ¡U? 2 rows between 105), the number of vertices and edges in the graph. The followingMLines contain three space-separated integersAI,BIAndCI(1? ¡U?AI,?BI? ¡U?N,AI? Too many?BI, 1? ¡U?CI? ¡U? 104), which means that there is an undirected edge fromAIToBIWith flow volumeCI.
It is guaranteed that there are no two edges connecting the same vertices; the given graph is connected; a solution always exists.
OutputOutputMLines, each containing one integerDI, Which shocould be 0 if the direction ofI-Th edge isAI? ~Ú?BI(The flow goes from vertexAITo vertexBI) And shoshould be 1 otherwise. The edges are numbered from 1MIn the order they are given in the input.
If there are several solutions you can print any of them.
Sample test (s) input3 33 2 101 2 103 1 5
Output101
Input4 51 2 101 3 102 3 54 2 153 4 5
Output00110
NoteIn the first test case, 10 flow units pass through path, and 5 flow units pass directly from source to sink :. <symbol · blank "http://www.bkjia.com/kf/ware/vc/" target = "_ blank" class = "keylink"> vcD4KPHA + Crj4s/bN + MLnwfe1xM7ez/keys/yoaPK18/IyejL + keys/keys + keys + CjxwPgo8cHJlIGNsYXNzPQ = "brush: java; "> # include # Include # Include # Include Typedef long LL; using namespace std; # define REPF (I, a, B) for (int I = a; I <= B; ++ I) # define REP (I, n) for (int I = 0; I <n; ++ I) # define CLEAR (a, x) memset (a, x, sizeof) const int maxn = 2*(1e5 + 100); struct node {int u, v, w; int num, next;} e [maxn <1]; int vis [maxn], head [maxn]; int pre [maxn], s [maxn]; int flow [maxn] [2]; int n, m, cnt; void add (int x, int y, int z, int n) {e [cnt]. u = x; e [cnt]. v = y; e [cnt]. w = z; e [cnt]. num = n; e [cnt]. next = head [x]; head [x] = cnt ++;} void BFS () {CLEAR (vis, 0); queue Q; q. push (1); vis [1] = 1; while (! Q. empty () {int st = q. front (); q. pop (); for (int I = head [st]; I! =-1; I = e [I]. next) {int v = e [I]. v; int num = e [I]. num; int w = e [I]. w; if (vis [v]) continue; s [num] = st; // Ç Â ¼ ± ß Æ flow ¼ µ ¶ ½ · ½ Ï ò flow [v] [1] + = w; flow [v] [0]-= w; if (v! = N & flow [v] [1] = flow [v] [0]) {vis [v] = 1; q. push (v) ;}}} int main () {int x, y, z; std: ios: sync_with_stdio (false ); while (cin> n> m) {CLEAR (head,-1); CLEAR (flow, 0); cnt = 0; REPF (I, 1, m) {cin> x> y> z; pre [I] = x; add (x, y, z, I); add (y, x, z, i); flow [x] [0] + = z; flow [y] [0] + = z;} BFS (); REPF (I, 1, m) {if (pre [I] = s [I]) puts ("0"); else puts ("1") ;}} return 0 ;}