#t537. 联络员
联络员
Tyvj Communication Network
Special for beginners, ^_^
Problem Description
Tyvj is already a year old, and the site has grown from a few initial users to tens of thousands. As the Tyvj site gradually grows, the number of administrators keeps increasing. As the liaison of Tyvj's management, you want to find some communication channels so that every pair of administrators can be in touch (directly or indirectly). Tyvj is a non-profit website without much profit, so you must keep the cost as low as possible.
You already know that Tyvj's communication channels fall into two categories: one is mandatory channels, which you must all include regardless of their price; the other is optional channels, from which you may pick some to form the final communication network among administrators. The data guarantees that the given channels can connect all administrators.
Input Format
The first line: , meaning Tyvj has administrators and there are communication channels.
Lines through : each line has four non-negative integers .
When , this channel is a mandatory channel.
When , this channel is an optional channel; means this entry describes a communication channel between administrators and : can receive 's messages and can also receive 's messages, and is the cost.
Output Format
The minimum communication cost.
Sample Input 1
5 6
1 1 2 1
1 2 3 1
1 3 4 1
1 4 1 1
2 2 5 10
2 2 5 5
Sample Output 1
9
Hint
1-2-3-4-1: there are four mandatory channels forming a cycle, so they can reach each other. To connect all administrators you need to connect administrator 2 and administrator 5; choose the channel of cost 5, so the total cost is 9.
There may be multiple communication channels between and ; your program should sum up all mandatory channels between and .
Constraints
1s, 1024KiB for each test case.
For of the data, .
For of the data, .
For of the data, .