#1274. 2278. [Poi2011]Garbage

2278. [Poi2011]Garbage

#2278. [Poi2011]Garbage

题目描述

The Byteotian Waste Management Company (BWMC) has drastically raised the price of garbage collection lately. This caused some of the citizens to stop paying for collecting their garbage and start disposing of it in the streets. Consequently, many streets of Byteburg are literally buried under litter.

The street system of Byteburg consists of n intersections, some of which are directly connected with bidirectional streets. No two streets connect the same pair of intersections. Some of the streets are littered while others are not.

The mayor of Byteburg, Byteasar, has decided on an unprecedented action to persuade the citizens to pay for waste collection. Namely, he decided to clean only some of the streets - precisely those that the majority of people living on paid for garbage collection. The streets that the majority of people living on did not pay for waste collection, on the other hand, will thus remain littered - or if it is called for - will become littered by the garbage collected from other streets! Byteasar has already prepared a city map with the streets to be cleaned and to remain or become littered marked on. Unfortunately, the BWMC employees cannot comprehend his master plan. They are, however, quite capable of carrying out simple instructions.

A single such instruction consists in driving the garbage truck along a route that starts on an arbitrary intersection, goes along any streets of choice, and ending on the very same intersection that it started on. However, every intersection can be visited at most once on a single route, except for the one it starts and ends with-the garbage truck obviously appears twice on that one. The truck cleans a littered street it rides along, but on the other hand it dumps the waste on the clean streets along its route, making them littered.

Byteasar wonders if it is possible to execute his plan by issuing a number of aforementioned route instructions. Help him out by writing a program that determines a set of such routes or concludes that it is impossible.

某国的街道很脏,可以开一些清理车去清理它们。
每次清理车走的路是一个环,清理完之后环上所有的街道改变状态(脏->不脏,不脏->脏)
给出初始状态和终止状态,求一个合法的清理车清理方案。

输入格式

There are two integers, separated by a single space, in the first line of the standard input: n and m (1<=N<=100000,1<=M<=1000000), denoting the number of intersections and the number of streets in Byteburg, respectively. The intersections are numbered from 1 to n. The following m lines specify successive streets, one per line. Each of those lines holds four integers separated by single spaces: a,b, s and t(1<=a<b<=N, s,t属于集合[0,1]). Such a quadruple specifies that the intersections a and b are connected with a street, tells if the street is currently littered (0 means clean, while 1 means littered), and tells if the street should be littered according to Byteasar's plan.

You may assume that if there exists a set of routes to carry out Byteasar's plan, then there is one in which the total number of streets that the garbage truck follows does not exceed 5*M.

In tests worth 60% of the points it additionally holds that m<=10000.

Input
第一行n,m (路口个数,街道个数)
下面m行,每行四个数x,y,z,w
x,y表示该街道连接的路口的编号,z表示初始时该街道的状态,w表示终止时该街道的状态(1=脏 0=不脏)
1<=n<=100000 1<=m<=1000000

输出格式

If there is no set of routes for the garbage truck to execute Byteasar's plan, then the word "NIE" ( no in Polish) should be printed out to the first and only line of the standard output. Otherwise, an arbitrary set of routes that does execute Byteasar's plan and has the truck move along no more than 5*m streets in total should be printed out. Then the first line should hold the number k of routes in the set. The following k lines should describe the routes, one per line. The -th line should start with a positive integer equal to the number of streets in the -th route. After a single space, numbers of successive intersections along the route should follow, separated by single spaces.

Example

The clean streets are drawn with a thin line in the figure, whereas the littered streets are drawn with a thick line. The streets that are to be clean are drawn with a dashed line, while those that are to be littered are drawn with a solid line.

如果不存在合法方案,输出NIE。
如果存在,第一行p,表示清理车的个数(要求p<=m*5)

样例

样例输入

6 8  

1 2 0 1  

2 3 1 0  

1 3 0 1  

2 4 0 0  

3 5 1 1  

4 5 0 1  

5 6 0 1  

4 6 0 1  

样例输出

2  

3 1 3 2 1   

3 4 6 5 4   

数据范围与提示

![image](file://smizad1.gif)