logo AlgoBeat OnlineJudge
登录 注册

#205291. [ICPC 2019 WF] Dead-End Detector

内存限制:1024 MiB 时间限制:5000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Warning: If you submit a malicious program, you will be banned.

警告:恶意提交本题将被封号。


The council of your home town has decided to improve road sign placement,especially for dead ends. They have given you a road map, and you must determine where to put up signs to mark the dead ends. They want you to use as few signs as possible.

The road map is a collection of locations connected by two-way streets. The following rule describes how to obtain a complete placement of dead-end signs. Consider a street connecting a location with another location. The -entrance of gets a dead-end sign if, after entering from , it is not possible to come back to without making a U-turn. A U-turn is a 180-degree turn immediately reversing the direction.

To save costs, you have decided not to install redundant dead-end signs, as specified by the following rule. Consider a street with a dead-end sign at its -entrance and another street with a dead-end sign at its -entrance. If, after entering from , it is possible to go to and enter without making a U-turn, the dead-end sign at the -entrance of is redundant. See Figure E.1 for examples.

Figure E.1: Illustration of sample inputs, indicating where non-redundant dead-end signs are placed.

输入格式

The first line of input contains two integers and , where is the number of locations and is the number of streets. Each of the following lines contains two integers and indicating that there is a two-way street connecting locations and . All location pairs in the input are distinct.

输出格式

On the first line, output , the number of dead-end signs installed. On each of the next lines, output two integers and marking that a dead-end sign should be installed at the -entrance of a street connecting locations and . The lines describing dead-end signs must be sorted in ascending order of -locations,breaking ties in ascending order of -locations.

样例

样例输入 1

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

样例输出 1

2
4 5
6 5

样例输入 2

8 8
1 2
1 3
2 3
3 4
1 5
1 6
6 7
6 8

样例输出 2

3
1 5
1 6
3 4

数据范围与提示

Source: ICPC World Finals 2019 Problem E.