Time limit: 3s
Memory limit: 256MB
Input:
Output:
Task
An undirected graph with nodes and edges is given.
Each edge is assigned two costs, and . It can be directed from to with a cost of , or from to with a cost of .
Choose a direction for each edge such that the resulting directed graph is acyclic and the sum of the costs is minimized.
Input data
The first line of the input contains two integers, and , representing the number of nodes and the number of edges in the graph.
The next lines each contain four integers, , , , and , indicating that there is an edge between nodes and with the properties described above.
Output data
The first line contains the integer , representing the required minimum cost.
Constraints and clarifications
- The input edges do not repeat.
# | Score | Restrictions |
---|---|---|
1 | 8 | |
2 | 21 | |
3 | 24 | |
4 | 7 | and the graph is connected. |
5 | 12 | Each node has an exact degree of . |
6 | 28 | No additional restrictions. |
Example
stdin
3 3
1 2 3 5
1 3 7 3
2 3 5 6
stdout
12
Explanation
The edges can be oriented as follows:
- with a cost of
- with a cost of
- with a cost of