#P3465. [POI2008] CLO-Toll

    ID: 2525 Type: RemoteJudge 1000ms 125MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>2008并查集POISpecial Judge

[POI2008] CLO-Toll

题目描述

King Byteasar has yielded under pressure of Byteotian merchants and hence decided to settle the issue of toll paid by them.

Byteotia consists of nn towns connected with mm bidirectional roads.

Each road connects directly two different towns and no two towns are connected by more than one direct road.

Note that the roads may lead through tunnels or flyovers.

Until now each town in Byteotia imposed duty on everyone who either entered or left the town.

The merchants, discontented with such situation, lodged a protest against multiple taxation.

King Byteasar ruled that the town privileges are now restricted.

According to the new royal edict, each town can only charge toll on merchants travelling by exact one road leading into the town, regardless of the direction they are travelling in.

Furthermore, for each road, those who travel it cannot be made to pay the duty to both towns the road connects.

It remains to determine which town should collect toll from which road.

Solving this problem His Highness has commissioned to you.

Task

Write a programme that:

  • reads the Byteotian road system's description from the standard input,

  • for each town determines on which road it should impose toll, or claims it is impossible,

  • writes out the result to the standard output.

输入格式

There are two integers in the first line of the standard input: nn and mm (1n100 0001 \le n \le 100\ 000, 1n200 0001 \le n \le 200\ 000), denoting the number of towns and roads in Byteotia, respectively. The towns are numbered from 11 to nn. In next mm lines descriptions of the roads follow. In line No. ii there are two integers aia_i and bib_i () meaning that towns aia_i and bib_i are directly connected by a road.

输出格式

If collecting the toll in accordance with the royal edict is impossible, your programme should write the word NIE ('no' in Polish) in the first and only line of the standard output. Otherwise, it should write the word TAK ('yes' in Polish) in the first line, while in the following nn lines should tell which city collects toll from which road. Line no. (i+1)(i+1) should tell on which road the town no. ii imposes toll. Since town no. ii is obviously one endpoint of this road, it is enough to tell what is the other endpoint. Thus if the town no. ii imposes toll on the road connecting it with the town no.jj , the line no. (i+1)(i+1) should contain the number jj. If more than one solution exists, write out one chosen arbitrarily.

题目大意

题目描述

给你 nn 个点和 mm 条双向边,问能否将其中的一些边改成有向边,使得只考虑有向边的情况下每个点的入度都为 11

输入格式

第一行输入 n,m(1n100000,1m200000)n,m(1≤n≤100000,1≤m≤200000) ,接下来 mm 行每行两个数 a,ba,b 表示点 aa 和点 bb 之间有一条双向边。输入保证没有重边与自环。

输出格式

若没有合法方案,输出 NIE\verb!NIE!,否则先在第一行输出 TAK\verb!TAK!,然后在第 i+1i+1 行输出点 ii 的入度是由哪个点出发的边所得到的。

感谢@hdxrie 提供的翻译。

4 5
1 2
2 3
1 3
3 4
1 4
TAK
3
3
4
1
4 3
1 3
3 4
2 3
NIE

提示

样例1:

样例2: