Mixed Integer Quadratic Programming
Time limit3sMemory limit1024 MB
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 vertices and directed edges. Vertex 1 is the source, and vertex is the sink. There are no multiple edges or self-loops.
- Each edge has a triple of integers . It always holds that , and there are at most 100 edges with .
- An edge with triple can carry up to units of resource. Sending units through it costs . 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 and , separated by a space. (, )
From the second line onward, the next lines describe the edges. The -th of these lines contains five integers , , , , , separated by spaces. They describe a directed edge from to with triple . (, , , , )
It is guaranteed that at most 100 edges have . It is also guaranteed that there are no multiple edges and no self-loops.
Output
Print two integers and on one line, separated by a space. is the maximum flow of the graph, and is the minimum cost that corresponds to the maximum flow. Note that the cost can be negative.