Misty
시간 제한1초메모리 제한2048 MB
모든 집이 연결되도록 하는 최소 총 길이의 길 집합을 찾아 그 길들의 번호를 출력한다.
문제
You have crashed your spaceship into a swampy planet. Luckily, you were rescued by a small 900-year-old green alien who lives at the base of a massive tree. Around the tree are many trails which lead to other alien's houses.
The green alien says he will repair your spaceship if you will help him with a very strange task. "Lots of mist, we have. Hard to see, it is. Help me light up my trails, you will," the alien says.
The green alien hands you a map of the trail system. There are houses, each labeled with a unique number between and , inclusive. There are trails, each of which goes between a pair of alien's houses. Each trail is labeled with a unique number between and , inclusive. The green alien has also marked the length of each of the trails.
The green alien shows you a reel of wire and a box of light-bulbs. "Be able to visit everyone else on lighted trails, everyone should. Minimum amount of wire and lights, you should use."
The green alien speaks quite strangely, so it takes a while for you to process this request. Then you realize that the alien wants you to light up the minimum length of trails so that every alien can visit every other alien by travelling only on lighted trails.
Your task is to determine which trails to light up.
입력
The first line contains two integers and (in that order).
The subsequent lines specify information about the trails labeled on the map, in sorted order (that is, information about trail is on the first line, trail on the second line, etc.). Each of the lines contain three integers, , , and (in that order). and specify the house numbers of the houses on opposite ends of the trail, and specifies the trail's distance.
출력
The first line of the output should contain , the number of trails which you need to light up.
The subsequent lines should contain the numbers corresponding to the trail labels which you need to light up.
제한
- All numbers on the same line are space separated.
- and
- For every , pair, .
- All and values are between and , inclusive.
- Every is an integer between and , inclusive.
- You are guaranteed that all of the houses can be connected by a set of trails.
- You are additionally guaranteed that there is at most one trail between any given , pair.