#P6472. [COCI 2008/2009 #6] SLICICE

[COCI 2008/2009 #6] SLICICE

Description

Because their pocket money is not enough, they came up with an idea: they form pairs, each person pays half the money, and they go to the store to buy two cards. Then they race to the fountain in the city center. The winner gets both cards. If they arrive at the same time, each takes one card.

One day, all the kids gathered together. They wanted to list all purchase records. However, their memories were a bit unclear: they only remembered part of the purchase records (and they do not know who got how many cards), but they did count how many cards each of them has. You need to write a program to help them reconstruct one possible set of purchase records.

Input Format

The first line contains two integers n,mn, m, representing the number of kids and the number of purchase records they still remember. Kids are numbered from 11 to nn.

The second line contains nn integers, where the ii-th integer is the number of cards owned by kid ii.

The next mm lines each contain two integers a,ba, b, meaning that kids aa and bb went to buy cards together once.

Output Format

Output the first line with an integer kk, the total number of purchases.

In the next kk lines, output three integers per line. The first two integers are the indices of the two kids in that purchase. The third integer is the number of cards won by the first kid in that race (0/1/20/1/2).

It is guaranteed that a solution exists. The total number of purchases is at most 10001000. If there are multiple valid solutions, output any one. This problem uses SPJ.

2 3
5 1
1 2
1 2
1 2
3
1 2 1
1 2 2
1 2 2
4 3
5 3 1 1
1 3
2 3
4 1
5
1 3 1
2 3 2
4 1 0
2 4 1
1 3 2
5 0
3 0 2 4 1
5
1 2 2
1 3 1
4 2 2
3 4 0
3 5 1

Hint

Constraints

For 100%100\% of the testdata, it is guaranteed that 1n1001 \le n \le 100, 0m10000 \le m \le 1000.

Notes

This problem is translated from COCI2008-2009 CONTEST #6 T6 SLICICE.

Translated by ChatGPT 5