Diversity


  • Time Limit : 2 second
  • Memory Limit : 256 megabytes

Shengdebao is quite a dreamer, thereby dreams a lot! In a dream he had last night people built a whole city named *"Shengdepolis"* in his favour! For the opening of this magnificent city people invited him on a tour expressing the city's impressive features. Shengdebao started describing it for you:

I entered the city and the first thing I noticed was nn towers, some of them were glowing with a beautiful purple light. There were some elevated railroads between some pairs of towers, each railroad was between two distinct towers. Some of the railroads were magical meaning they could disappear! The highlighted thing was the city's diverse architecture. The lighting of the towers were related to the visible railways. By paying close attention I found out that at any point of time a tower glows purple only when there are Odd number of visible railroads connected to them. Some of the railways aren't magical and so are always visible, these railroads are always counted in their adjacent towers.

Their tour program was also interesting! The tour contained a set of turns, in each turn I start by observing the city from a purple luminous tower. A helicopter then comes and takes me to another glowing tower. In both before and after the trip with the helicopter I take a glance at the landscape. Then after I've took a glance at the landscape on the second tower, the magic happens! some of the magical railroads appear and some disappear, leading to a change in the city's lighting (it is possible that the city doesn't change at all), but the change must be in a way that the tower I'm on top of stays luminous (meaning odd number of visible railways should stay connected to it). After the change, the turn ends starting a new turn afterwards or ending the tour. These turns start from one Tower and should end at the same tower.

I remember agreeing to this tour in two conditions:

  • For all possible ways of architectures (meaning the ways which magical railways are visible or not) and every glowing tower in that form I should have a view of the city from the top of that tower. meaning if we have xx magical railways, for all 2x2^x possible city formats and each glowing tower in every format I should have at least one glance of that landscape in either before or after my trip with the helicopter in a turn.

  • The number of *"turns"* should be minimized.

The story ends!

Shengdebao has an identical memory and remembers each detail about the magical city. But he didn't keep track of the number of turns in his tour so you should help him find out a valid tour with minimum size. Also if the number of turns in the dreamy tour is more than 1 000 0001\ 000\ 000 the fact that Shengdebao is lying about his dream is in prospect! so if there is no tour with less than 1 000 0001\ 000\ 000 turns, you should say he is lying!

Input🔗

In the input Shengdepolis is given. First line contains n,mn , m the number of towers and railways respectively. Then in the next mm lines the explanation of each railroad is given by three integers t,u,vt , u , v. tt is either 00 or 11 if it is 00 it means that the railway between towers number vv and uu is not magical and if t=1t = 1 then it is magical.

1n,m171 \le n , m \le 17

0t1,1u,vn,uv0 \le t \le 1 , 1 \le u , v \le n , u \neq v

It is possible for two railways to be exactly the same.

Output🔗

In the first line of output you should write the minimum number of turns in the imaginary tour represented as a number kk. Then if kk is greater than 1 000 0001\ 000\ 000 you should display *"lie"* and end the program. If the condition k1 000 000k \le 1\ 000\ 000 holds you should output kk lines each consisting of 3 integers u,mask,vu , mask , v. uu represents the tower on which Shengdebao starts that turn and vv shows the one which he ends at after riding the helicopter. maskmask is a code showing the architecture of the city. A code of a city format is described below:

maskmask is a number less than 2m2 ^ m that when written in the binary notation the iith bit is either equal to 00 or 11 if it is equal to 00 it means that the iith edge is invisible in this form and otherwise this bit is 11. The number of each edge is in the order appeared in the input. By this explanation there does not exist any maskmask in which its iith bit is 00 with also the first integer in the i+1i+1th line of input being 00 at the same time.

To clarify, in each line uu and vv both have Odd number of visible railways connected to them in the format coded as maskmask. The iith line's third number should be equal to the i+1i+1th line's first number and the first number of the first line should be equal to the last number of the kkth line.

If there are multiple tours satifsying the criteria, you can output an arbitrary one.

Examples🔗

Sample input 1🔗

3 2
0 1 2
0 2 3
Plain text

Sample output 1🔗

2
1 3 3
3 3 1
Plain text

Explanation: No railroad is magical so always towers 11 and 33 have 11 visible adjacent railroads and they are always visible and the code is always 33 (both railways are visible). By considering that the tour should contain the only architecture from both scenes from tower 11 and 33, and also the fact that we should return to the same tower, its best to go from 11 to 33 and return back to 11 again.

Sample input 2🔗

4 6
0 1 2
0 2 3
0 3 4
0 4 1
1 1 3
1 2 4
Plain text

Sample output 2🔗

4
1 63 4
4 47 2
2 63 3
3 31 1
Plain text

Sample input 3🔗

3 2
0 1 2
1 2 3
Plain text

Sample output 3🔗

4
1 3 3
3 3 1
1 1 2
2 1 1
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.