Road Planner
Time limit1sMemory limit128 MB
Given a DAG with linear latency functions per edge, distribute an integer number of cars from source to sink to reach Wardrop (selfish routing) equilibrium and output the floor of the equilibrium travel time.
- Level
Hard9 of 10
- Topics
- Graph, Math, Binary search
- Solved
- No attempts yet
Problem
An acyclic road network is composed of unidirectional road segments (edges), each connecting two intersections (vertices) out of a total of intersections. The time necessary to travel on a road segment is always positive and it depends linearly on the number of cars using the segment :
and are two constants expressed as single precision floating point numbers, describing the properties of road segment . The time necessary to cross an intersection is .
A number of cars must travel from vertex to vertex in this road network. Each car chooses its route selfishly in order to reduce its own travel time; each car knows that all the other cars will also selfishly choose their route. You are asked to write a program that computes how many cars will travel on each of the possible paths from the source to the destination, and the time needed to travel on those paths.
Input
The input contains several tests and is organized as follows. The first line contains the number of tests. The following lines contain the specification of the tests. Each test contains on the first line the number of vertices, the number of edges and the number of cars, separated by whitespaces. After that, each edge is given on a separate line and contains the following fields separated by spaces: source vertex, destination vertex, and .
Output
The output will contain one line for each test input, specifying the minimum time for any car to travel in the network, rounded down to the nearest integer.
Hint
The first input consists of vertices and edges; cars must travel from vertex to vertex . To achieve the smallest travel time, cars will choose one of the two possible paths and such that the number of cars on both is equal; hence the minimum travel time is .
The second input is similar to the first one, except for a zero-cost edge that is added between vertices and . In this case, all cars selfishly choose to take the path and the minimum travel time is .