This page is still under construction.

Parts of this page are still being built. What you see may change.

Semiconductor Fabrication

Time limit4sMemory limit1024 MB

Summary
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 NN vertices and MM edges. Vertices are numbered from 11 to NN, and vertex ii has potential energy EiE_i. Potential energies are real numbers, with E1=1.0E_1=1.0 and EN=−1.0E_N=-1.0 fixed. Hanbyeol can choose the potential energies of the other vertices freely. Vertices 11 and NN are special: no edge enters vertex 11, and no edge leaves vertex NN.

An edge e=(u,v)e=(u,v) can carry positive energy and negative energy from uu to vv. Each edge has an energy transfer efficiency. If Hanbyeol sends positive energy pe(≥0)p_e(\ge 0) and negative energy me(≤0)m_e(\le 0) through an edge with positive efficiency ae(≥0)a_e(\ge 0) and negative efficiency be(≥0)b_e(\ge 0), the edge transfers (aepe+beme)(a_e p_e + b_e m_e) energy. If the energy sent through edge e=(u,v)e=(u,v) does not satisfy p(u,v)+m(u,v)≥Eu−Evp_{(u,v)}+m_{(u,v)} \ge E_u - E_v, 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 NN and the number of edges MM, separated by a space. (3≤N≤5003\le N\le 500, 1≤M≤N(N−1)1\le M\le N(N-1))

Each of the next MM lines contains four integers uu, vv, aa, bb, separated by spaces. This means there is an edge from vertex uu to vertex vv with positive efficiency aa and negative efficiency bb. No duplicate edges are given. (1≤u,v≤N1\le u,v\le N, u≠vu\ne v, 0≤a,b≤1090\le a,b\le 10^9)

Output

Print the minimum cost of making one semiconductor. If the cost can be less than −3×10−9-3\times 10^{-9}, 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 10−910^{-9} is accepted. No input has an answer that is at least −3×10−9-3\times 10^{-9} and less than −1×10−9-1\times 10^{-9}.

Examples2

  1. Example 1

    Input
    3 2
    1 2 4 2
    2 3 2 1
    
    Expected output
    4.00
    
  2. Example 2

    Input
    3 2
    1 2 2 4
    2 3 1 2
    
    Expected output
    HAPPY