Walk Through the Forest

题目描述

[problemUrl]: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=21&page=show_problem&problem=1858 [PDF](https://uva.onlinejudge.org/external/109/p10917.pdf) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA10917/2cdbcbd2041975ba19703cf570f7a4087f3eb461.png)

输入输出格式

输入格式


![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA10917/022b71bb9cb1ef7722eafa8c8a774ab2ecc38148.png)

输出格式


![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA10917/b53d3ce908136ede18b278727a3e9aeb6d23bbaf.png)

输入输出样例

输入样例 #1

5 6
1 3 2
1 4 2
3 4 3
1 5 12
4 2 34
5 2 24
7 8
1 3 1
1 4 1
3 7 1
7 4 1
7 5 1
6 7 1
5 2 1
6 2 1
0

输出样例 #1

2
4