[6 Universities joint training provincial election courier # 20]

Description

Topic Link

New Year approaching, C school \ (m \) bit the students because the home life is too boring, each of them bought a courier.

They live in the street, this street \ (n-\) th cell, the \ (I \) th cell \ ((1 \ le i \ le n) \) only the first \ (i + 1 \) a cell connected to the second \ (i + 1 \) from a cell is \ (D_i \) . The first \ (i \) bit the students live at the \ (p_i \) plots, violent degree the student is \ (D_i \) .

You as a courier company owner, you want to prepare the final day of the New Year's finish this \ (m \) a list of the students ran the road. Express exactly \ (m \) postman, the postman can be up to each one's Express (specifically who is designated by you) sent on the last day \ (q_i \) plots, then call this person to pick up the courier.

If a postman on the last day of the New Year to work, he would have \ (c_i \) is unhappy value, but after seeing the students, because the students very irritable, and went a long journey, he passed to the courier \ (\ text {this temper degree students} + \ text {the students are moving away} \) is unhappy value. The courier will ask for his unhappy equivalent to the value of the tip.

Under pressure off you have to mutter a few students express, think know that for all \ ((1 \ le i \ le m) \) If you send \ (m \) classmates courier, you need a minimum number of tips paid .

\ (N \ 800, m \ the 50000 \)

Solution

First, you can simply have to run the network stream to obtain \ (30 \) score good results.


Then consider how to optimize the complexity of the \ (O (nm) \) a.

Obviously not avoid \ (m \) augmentation, so consider the optimization of a time complexity augmented to \ (O (n-) \) , consider a first method of FIG construction: middle \ (n-\) points represents \ (n-\) th cell and the first \ (I \) and \ (i + 1 \) connected between a bidirectional edge dot, costs \ (D_i \) , flow \ (\ INF \ ) , then for every student, even an edge \ (S \ rightarrow P_i \) , cost of \ (D_i \) , flow \ (1 \) , then for each courier, even an edge \ (q_i \ t rightarrow \) , cost of \ (C_i \) , flow \ (1 \) .

Clearly, for the first \ (I \) points, \ (S \ rightarrow P_i \) and \ (q_i \ rightarrow t \) only a minimum weight that is useful side, a rear side and not through the back flow can not be , so consider a time into the useful side to run spfa augmented .

So we get the theoretical complexity \ (O (knm) \) approach, which \ (k \) is the average number of spfa each point into the team, looks very capable too , then you find that you run a large data \ (5S \) , and then you looked at the number of times each point, he did not find a lot, people of conscience to the topic and no card spfa. So you try to wave the card often, the card to the \ (1.5s \) after discovering card does not move.

The main reason is that the card does not move, this constant practice too much, my card technology often not enough to put his card in the past.

Consider a better approach, a positive recording down (from \ (I \) come \ (I. 1 + \) ), and the number of back flow can go backwards, and then by reverse each respective sweep over the way to find the shortest path be augmented to being a sweep, for example, which would be the most recent recording can reach the nearest point of the current students, and then the current courier match point, each update from the current point of closest distance students.

So we got a complexity is really \ (O (nm) \) approach.

Code

Guess you like

Origin www.cnblogs.com/wasa855/p/12607791.html