Semiconductor Fabrication
Time limit4sMemory limit1024 MB
Choose vertex potentials and edge energies, with E1=1.0 and EN=-1.0 fixed, to minimize total transfer cost, or print HAPPY if the cost can drop below zero.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, Math
- Solved
- No attempts yet
Problem
Hanbyeol wants to donate a few semiconductors that he built himself to the juniors who will join the national collegiate programming contest club federation before he graduates. To make as many semiconductors as possible, he wants to minimize the cost of making one.
A semiconductor is a directed graph with vertices and edges. Vertices are numbered from to , and vertex has potential energy . Potential energies are real numbers, with and fixed. Hanbyeol can choose the potential energies of the other vertices freely. Vertices and are special: no edge enters vertex , and no edge leaves vertex .
An edge can carry positive energy and negative energy from to . Each edge has an energy transfer efficiency. If Hanbyeol sends positive energy and negative energy through an edge with positive efficiency and negative efficiency , the edge transfers energy. If the energy sent through edge does not satisfy , the edge may overload and the semiconductor may break.
The cost of a semiconductor is the total energy transferred by all its edges. Help Hanbyeol choose the potential energies and the energy sent through each edge so that the semiconductor does not break and the cost is minimized.
Input
The first line contains the number of vertices and the number of edges , separated by a space. (, )
Each of the next lines contains four integers , , , , separated by spaces. This means there is an edge from vertex to vertex with positive efficiency and negative efficiency . No duplicate edges are given. (, , )
Output
Print the minimum cost of making one semiconductor. If the cost can be less than , print HAPPY, the word for the feeling Hanbyeol has when he earns money every time he produces a semiconductor. Absolute or relative error up to is accepted. No input has an answer that is at least and less than .