#graph1006. 最小割

最小割

Minimum Cut

Problem Source

AHOI 2009

Problem Description

Countries A and B are at war. In country A's material transport network there are NN transit stations and MM one-way roads. Suppose the ii-th road (1≤i≤M1 \leq i \leq M) connects transit stations viv_i and uiu_i; then transit station viv_i can reach transit station uiu_i via this road, and cutting this road costs cic_i.

Now country B wants to find a set of roads to cut so that transit station ss can no longer reach transit station tt, while minimizing the total cutting cost.

Little Cocoa immediately saw that this is a minimum-cut problem. But the thoughtful Little Cocoa is not satisfied with just that. For each one-way road he now raises two questions:

  • Question 1: Is there a minimum-cost cutting plan in which this road is cut?
  • Question 2: Is this road cut in every minimum-cost cutting plan?

Please answer these two questions for each road.

Input Format

The first line contains four positive integers N,M,s,tN, M, s, t (N≤4000, M≤60000N \leq 4000,\ M \leq 60000).

Lines 22 to M+1M+1 each contain three positive integers v,u,cv, u, c, indicating a one-way road from transit station vv to transit station uu with cutting cost cc (1≤c≤1000001 \leq c \leq 100000).

Note: there may be multiple roads directly connecting the same pair of transit stations.

Output Format

For each one-way road, in the order they were input, output one line containing two integers that are each either 00 or 11, representing the answers to question 1 and question 2 respectively (11 means yes, 00 means no).

Sample Input

6 7 1 6
1 2 3
1 3 2
2 4 4
2 5 1
3 5 5
4 6 2
5 6 3

Sample Output

1 0
1 0
0 0
1 0
0 0
1 0
1 0

Hint

Let the edge from the (i+1)(i+1)-th input line be edge ii. Then {1,2},{6,7},{2,4,6}\{1, 2\}, \{6, 7\}, \{2, 4, 6\} are the only three minimum-cost cutting plans. Their union is {1,2,4,6,7}\{1, 2, 4, 6, 7\}, and their intersection is {∅}\{\varnothing\}.