ZOJ3378 两点间的必经之路 tarjan算法

Attack the NEET Princess


Time Limit: 9 Seconds      Memory Limit: 65536 KB


Houraisan Kaguya ( 蓬萊山輝夜) is the NEET (not in education, employment or training) princess living in Eientei ( 永遠亭). She is an unemployed geek, who sits at home and surfs the Internet all day. But today is different, as the Hakurei Shrine Reitaisai Festival ( 博麗神社例大祭) will be hosted in Hakurei Shrine , Kaguya decides to go to buy some new doujin games.


Fujiwara no Mokou ( 藤原妹紅) detests Kaguya, and has been planing to attack her for a long time. But she nerver got the chance before because Kaguya kept staying in Eientei , under the protection of Yagokoro Eirin ( 八意永琳). Knowing that Kaguya will go outside today, Mokou decides to wait on certain road and attack her once she passes there. Mokou don't know which path Kaguya will choose, but she thinks that there always exits some roads where she can always meet Kaguya.

Input

There are multiple cases. Each case begins with two integers 2 ≤ n ≤ 10000 -- the number of villages and 2 ≤ m ≤ 100000 -- the number of roads. Then m lines, each contains two integers a and b (0 ≤ a , b < n), indicating a road connecting village a and village b . Village 0 is Eientei and Village n -1 is Hakurei Shrine . They are always connected by roads. There may be more than one roads between two villages.

Output

Find out the roads where Mokou can always meet Kaguya. For each case, output the number of roads in the first line, then output the numbers of the roads in ascending order in the second line.

Sample Input

3 2

0 1

1 2

 

7 8

0 1

0 2

1 3

2 3

3 4

3 5

4 6

5 6

 

Sample Output

2

0 1

0

 

 

求起点到终点之间的必经之路 , 思路是 : 首先用 tarjan 算法求出图中的所有割边 , 然后从起点开始 BFS 到终点搜出一条路径 , 把路径上的边和已求出的割边求交集就可以得出必经之路 .

 

代码如下 :

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值