CF269C Flawed Flow
Description
Emuskald considers himself a master of flow algorithms. Now he has completed his most ingenious program yet — it calculates the maximum flow in an undirected graph. The graph consists of $ n $ vertices and $ m $ edges. Vertices are numbered from 1 to $ n $ . Vertices $ 1 $ and $ n $ being the source and the sink respectively.
However, his max-flow algorithm seems to have a little flaw — it only finds the flow volume for each edge, but not its direction. Help him find for each edge the direction of the flow through this edges. Note, that the resulting flow should be correct maximum flow.
More formally. You are given an undirected graph. For each it's undirected edge ( $ a_{i} $ , $ b_{i} $ ) you are given the flow volume $ c_{i} $ . You should direct all edges in such way that the following conditions hold:
1. for each vertex $ v $ $ (1<v<n) $ , sum of $ c_{i} $ of incoming edges is equal to the sum of $ c_{i} $ of outcoming edges;
2. vertex with number $ 1 $ has no incoming edges;
3. the obtained directed graph does not have cycles.
Input Format
The first line of input contains two space-separated integers $ n $ and $ m $ ( $ 2
Output Format
Output $ m $ lines, each containing one integer $ d_{i} $ , which should be 0 if the direction of the $ i $ -th edge is $ a_{i}→b_{i} $ (the flow goes from vertex $ a_{i} $ to vertex $ b_{i} $ ) and should be 1 otherwise. The edges are numbered from 1 to $ m $ in the order they are given in the input.
If there are several solutions you can print any of them.
Explanation/Hint
In the first test case, 10 flow units pass through path , and 5 flow units pass directly from source to sink: .