Under construction

Still being built. Things may change

Mixed Integer Quadratic Programming

Time limit3sMemory limit1024 MB

Summary
Find the max flow from vertex 1 to vertex n and its minimum cost, where each edge's cost is a x^2 + b x for flow x.
Level

Medium6 of 10

Topics
Shortest path, Graph, Greedy
Solved
No attempts yet

Problem

Sorry, I did not prove that this problem is in P. In other words, this problem may not be in P. But since I solved it, I believe it is not a problem that humans cannot solve.

흐즈로

Time limit: 3000 ms. Memory limit: 1024 MB.

You must solve a modified minimum cost maximum flow problem. The modified problem has the following conditions.

  • The graph has nn vertices and mm directed edges. Vertex 1 is the source, and vertex nn is the sink. There are no multiple edges or self-loops.
  • Each edge has a triple of integers (a,b,c)(a,b,c). It always holds that 0≤a0 \le a, and there are at most 100 edges with a≠0a \neq 0.
  • An edge with triple (ai,bi,ci)(a_i,b_i,c_i) can carry up to cic_i units of resource. Sending xx units through it costs aix2+bixa_i x^2+b_i x. The cost can be negative.
  • The amount of resource sent through each edge must be a non-negative integer.

The following conditions from the standard minimum cost maximum flow problem also apply.

  • You must maximize the amount of resource sent from the source to the sink, and at the same time minimize the required cost.
  • The amount leaving the source equals the amount entering the sink.
  • For every vertex other than the source and the sink, the amount entering equals the amount leaving.

Given the graph that satisfies these conditions, write a program that solves the problem and prints the maximum flow and the minimum cost.

Input

The first line contains two integers nn and mm, separated by a space. (2≤n≤2002 \le n \le 200, 1≤m≤min⁡(n(n−1),1500)1 \le m \le \min(n(n-1),1500))

From the second line onward, the next mm lines describe the edges. The ii-th of these lines contains five integers uiu_i, viv_i, aia_i, bib_i, cic_i, separated by spaces. They describe a directed edge from uiu_i to viv_i with triple (ai,bi,ci)(a_i,b_i,c_i). (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \ne v_i, 0≤ai≤2000 \le a_i \le 200, −200≤bi≤200-200 \le b_i \le 200, 1≤ci≤101 \le c_i \le 10)

It is guaranteed that at most 100 edges have ai≠0a_i \neq 0. It is also guaranteed that there are no multiple edges and no self-loops.

Output

Print two integers ff and cc on one line, separated by a space. ff is the maximum flow of the graph, and cc is the minimum cost that corresponds to the maximum flow. Note that the cost can be negative.

Examples1

  1. Example 1

    Input
    6 6
    1 2 0 1 5
    2 3 1 0 3
    2 4 0 2 3
    3 5 0 -1 10
    4 5 0 0 10
    5 6 1 0 5
    
    Expected output
    5 38