CF BUDDY
← Problems·

1842D · Tenzing and His Animal Friends

1900 · constructive algorithms, graphs, greedy

Problem: Tenzing has nn animal friends. He numbers them from 11 to nn.

One day Tenzing wants to play with his animal friends. To do so, Tenzing will host several games.

In one game, he will choose a set SS which is a subset of {1,2,3,...,n}\{1,2,3,...,n\} and choose an integer tt. Then, he will play the game with the animals in SS for tt minutes.

But there are some restrictions:

  1. Tenzing loves friend 11 very much, so 11 must be an element of SS.
  2. Tenzing doesn't like friend nn, so nn must not be an element of SS.
  3. There are m additional restrictions. The ii-th special restriction is described by integers uiu_i, viv_i and yiy_i, suppose xx is the total time that exactly one of uiu_i and viv_i is playing with Tenzing. Tenzing must ensure that xx is less or equal to yiy_i. Otherwise, there will be unhappiness.

Tenzing wants to know the maximum total time that he can play with his animal friends. Please find out the maximum total time that Tenzing can play with his animal friends and a way to organize the games that achieves this maximum total time, or report that he can play with his animal friends for an infinite amount of time. Also, Tenzing does not want to host so many games, so he will host at most n2n^2 games.

Input Format: The first line of input contains two integers nn and mm (2n1002 \leq n \leq 100, 0mn(n1)20 \leq m \leq \frac{n(n-1)}{2}) — the number of animal friends and the number of special restrictions.

The ii-th of the following mm lines of input contains three integers uiu_i, viv_i and yiy_i (1ui<vin1\leq u_i<v_i\leq n, 0yi1090\leq y_i\leq 10^9) — describing the ii-th special restriction. It is guaranteed that for 1i<jm1 \leq i < j \leq m, (ui,vi)(uj,vj)(u_i,v_i) \neq (u_j,v_j).

Output Format: If Tenzing can play with his animal friends for an infinite amount of time, output "inf". (Output without quotes.)

Otherwise, in the first line, output the total time TT (0t10180 \leq t \leq 10^{18}) and the number of games kk (0kn20 \leq k \leq n^2).

In the following kk lines of output, output a binary string ss of length nn and an integer tt (0t10180 \leq t \leq 10^{18}) — representing the set SS and the number of minutes this game will be played. If si=1s_i=\texttt{1}, then iSi \in S, otherwise if si=0s_i=\texttt{0}, then iSi \notin S.

Under the constraints of this problem, it can be proven that if Tenzing can only play with his friends for a finite amount of time, then he can only play with them for at most 101810^{18} minutes.

Note: In the first test case:

  1. Tenzing will host a game with friend {1}\{1\} for 11 minute.
  2. Tenzing will host a game with friends {1,4}\{1,4\} for 11 minute.
  3. Tenzing will host a game with friends {1,3}\{1,3\} for 11 minute.
  4. Tenzing will host a game with friends {1,2,3,4}\{1,2,3,4\} for 11 minute.

If after that, Tenzing host another game with friends {1,2}\{1,2\} for 11 minute. Then the time of exactly one of friends 22 or 33 with Tenzing will becomes 22 minutes which will not satisfy the 33-rd special restriction.

In the second test case, there is no special restrictions. So Tenzing can host a game with friend {1}\{1\} for an infinite amount of time.

Sample Cases

Case 1

Input

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

Output

4 4
10000 1
10010 1
10100 1
11110 1

Case 2

Input

3 0

Output

inf

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback