Heavy Transportation

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chimchim04/article/details/79969969

Heavy Transportation

Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight. 
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know. 

You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.
The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.
The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.
Sample Input
3 3
1 2 3
1 3 4
2 3 5
Sample Output
Scenario #1:



#define N 1005
#define inf 0x3f3f3f
using namespace std;
int map[N][N],dis[N],vis[N];
int n;
int dij(int s,int e)
    for(int i=1;i<=n;i++)
    int ans,u;
    for(int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
            if (!vis[j]&&dis[j]>ans)
        for (int j=1;j<=n;j++)
    return dis[e];
int main()
    int t,m,a,b,x,k=1;
    while (t--)
        scanf("%d %d",&n,&m);
        for (int i=0;i<m;i++)
        printf("Scenario #%d:\n%d\n\n",k++,dij(1,n));
    return 0;




Problem DescriptionnRuratania is just entering capitalism and is establishing new enterprising activities in many fields in- cluding transport. The transportation company TransRuratania is starting a new express train from city A to city B with several stops in the stations on the way. The stations are successively numbered, city A station has number 0, city B station number m. The company runs an experiment in order to improve passenger transportation capacity and thus to increase its earnings. The train has a maximum capacity n passengers. The price of the train ticket is equal to the number of stops (stations) between the starting station and the destination station (including the destination station). Before the train starts its route from the city A, ticket orders are collected from all onroute stations. The ticket order from the station S means all reservations of tickets from S to a fixed destination station. In case the company cannot accept all orders because of the passenger capacity limitations, its rejection policy is that it either completely accept or completely reject single orders from single stations.nnWrite a program which for the given list of orders from single stations on the way from A to B determines the biggest possible total earning of the TransRuratania company. The earning from one accepted order is the product of the number of passengers included in the order and the price of their train tickets. The total earning is the sum of the earnings from all accepted orders. nn nnInputnThe input file is divided into blocks. The first line in each block contains three integers: passenger capacity n of the train, the number of the city B station and the number of ticket orders from all stations. The next lines contain the ticket orders. Each ticket order consists of three integers: starting station, destination station, number of passengers. In one block there can be maximum 22 orders. The number of the city B station will be at most 7. The block where all three numbers in the first line are equal to zero denotes the end of the input file.n nnOutputnThe output file consists of lines corresponding to the blocks of the input file except the terminating block. Each such line contains the biggest possible total earning. n nnSample Inputn10 3 4n0 2 1n1 3 5n1 2 7n2 3 10n10 5 4n3 5 10n2 4 9n0 2 5n2 5 8n0 0 0n nnSample Outputn19n34

Heavy Cargo


Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their latest model, the Godzilla V12, is so big that the amount of cargo you can transport with it is never limited by the truck itself. It is only limited by the weight restrictions that apply for the roads along the path you want to drive.nGiven start and destination city, your job is to determine the maximum load of the Godzilla V12 so that there still exists a path between the two specified cities.nnnInputnnThe input will contain one or more test cases. The first line of each test case will contain two integers: the number of cities n (2 <= n <= 200) and the number of road segments r (1 <= r <= 19900) making up the street network. nnThen r lines will follow, each one describing one road segment by naming the two cities connected by the segment and giving the weight limit for trucks that use this segment. Names are not longer than 30 characters and do not contain white-space characters. Weight limits are integers in the range 0 - 10000. Roads can always be travelled in both directions. nnThe last line of the test case contains two city names: start and destination. nnInput will be terminated by two values of 0 for n and r.nnnOutputnnFor each test case, print three lines:nna line saying "Scenario #x" where x is the number of the test casena line saying "y tons" where y is the maximum possible loadna blank linennSample Inputnn4 3nKarlsruhe Stuttgart 100nStuttgart Ulm 80nUlm Muenchen 120nKarlsruhe Muenchenn5 5nKarlsruhe Stuttgart 100nStuttgart Ulm 80nUlm Muenchen 120nKarlsruhe Hamburg 220nHamburg Muenchen 170nMuenchen Karlsruhen0 0nnnSample OutputnnScenario #1n80 tonsnnScenario #2n170 tons

Apple Transportation


There's a big apple tree in the forest. In the tree there are N nodes (numbered from 0 to N - 1), and the nodes are connected by branches. On each node of the tree, there is a squirrel. In the autumn, some apples will grow on the nodes. After all apples are ripe, each squirrel will collect all the apples of their own node and store them. For the demand to be harmonic, they decide to redistribute the apples to minimize the variance (please refer to the hint) of apples in all nodes. Obviously, an apple cannot be divided into several parts. To reach this goal, some transportation should be taken. The cost of transporting x apples from node u to node v is x * distance (node u, node v). Now given the current amount of apples of each node and the structure of the apple tree, you should help the squirrels to find the minimal cost to redistribute the apples.nnInputnnInput consists of multiple test cases (less than 80 cases)!nnFor each test case, the first line contains an integer N (1 <= N <= 100), which is the number of the nodes in the tree.nnThe following line contains N integers a0,a1,...,aN-1 (0 <= ai <= 10000), representing the amount of the i-th node's apples.nnThe following N - 1 lines each contain three integers u, v, c (0 <= u,v <= N - 1, 0 <= c <= 1000), which means node u and node v are connected by a branch, the length of the branch is c.nnThere is a blank line between consecutive cases.nnOutputnnFor each case output the minimal total transportation cost. The minimal cost is guaranteed to be less than 231.nnSample Inputnn3n1 2 3n0 1 1n0 2 1nn3n1 3 3n0 1 3n0 2 4nn2n1 2n0 1 1nSample Outputnn1n3n0

Goods Transportation


The transportation problem is to minimize the cost of transporting good from m source nodes to n destination nodes through arcs. Arcs are directed routes from source to destination which have no capacity limitation, but there is a cost associated with each arc for each unit of goods transported through. Each source has a supply amount, and each destination has a demand amount.nIn this problem, the source nodes are numbered from 1 to m, and the destination nodes are numbered from 1 to n. There is one arc between each pair of the source node and the destination node. The cost of the arc originated from source node a (1 <= a <= m) to destination node b (1 <= b <= n) is a + b. The supply for each source nodes and the demand for each destination node are also given. You are going to calculate the maximal possible amount of goods that can be transported from source to destination, and also the minimized cost to achieve that goal.nnInput DescriptionnnStandard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 10) which is the number of test cases. T test cases follow, each preceded by a single blank line.nnFor each case, the numbers of source and destination nodes, m (1 <= m <= 10,000) and n (1 <= n <= 10,000), are given in the first line. The next line contains m integers, which are the supply amounts for each source, and the next line n integers, which are the demand amounts of each destination. All supply and demand amounts are non-negative numbers less than or equal to 10,000.nnOutput DescriptionnnResults should be directed to standard output. Start each case with "Case #:" on a single line, where # is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.nnFor each test case print in one line the two integers - the maximal amount of goods that can be transported to destination, and the minimized cost for transporting those goods. Separate them with a single space.nnSample Inputnn3nn3 4n2 5 6n4 3 1 5nn1 1n3n7nn3 2n1 1 1n1 1nnSample OutputnnCase 1:n13 63nnCase 2:n3 6nnCase 3:n2 6

Transportation Network


A transportation network consists of a central node and some other nodes directly or indirectly (through some intermediate nodes) connected to the central node, and also the transporting channels which connect them. It is known that for any node in the transportation network there is exactly one path leads to the central. Every channel has its own length, the distance between any two nodes is defined as the total length their shortest path. nnFor example, in the following transportation network (the numbers in the parentheses represents the length of the channels):nn 1n /\n(2) / \ (3)n 2 3n(2)| |(2)n | |n 4 5nnThe distance between 2 and 3 is 5, the distance between 1 and 4 is 4, and the distance between 3 and 5 is 2.nnTwo transportation network can be combined, combining network A to network B means building a channel that connects the central of A and the central of B, and take the central of B as the central of the combined network. That combined network contains all the nodes and channels that is in network A or in network B.nnCountry-A has N (3 <= N <= 20,000) nodes that needs transporting between. Initially there is no channel between them, and each node is a solo transportation network. For the transporting the substance more expediently, Country-A has decided to build some transporting channels.nnTo maintain the information of the networks, Country-A has bought a super computer, which can receive and execute two kinds of instructions:nn1) Q i j (1 <= i, j <= N, i <> j)nnQuerying the distance between node i and node j in the network. If they are not in the same network, output "Not connected." (Without quotation), output the distance otherwise.nn2) U i j l (1 <= i, j <= N, node i and node j are not in the same network)nnCombine the network containing i to the network containing j, makes the channel between them be l. (l is an integer, and 0 < l <= 1,000)nTo avoid hackers' invasion which may cause the leak of the information, you should input the instruction U i' j' l instead of U i j l (where i' = (i + last_result) mod n + 1, j' = (j + last_result) mod n + 1 here last_result is the result of last valid query (i.e. the query that i and j are in the same network). Initially last_result = 0.nnYour task is to write the program for the super computer.nnnInputnnThe first line of the input is an integer X (0 < X <= 6) represents number test cases of this problem. Then X blocks each representsna test case.nnThe first line of each block contains two numbers N and M (5 <= M <= 40,000) representing country-A has N transportation nodes and the super computer will receive M instructions. Then M lines each represents an instruction, has the format Q i j or U i' j' l, which has been described above.nnThere're NO breakline between two continuous test cases.nnnOutputnnFor each querying output one line an integer represents the distance or "Not connected." (Without quotation)nnThere're NO breakline between two continuous test cases.nnnSample Inputnn2n4 6nU 3 4 4nQ 2 3nU 3 2 2nQ 1 2nU 2 3 1nQ 2 4n4 6nU 3 4 4nQ 2 3nU 3 2 2nQ 1 2nU 2 3 1nQ 2 4nnnSample Outputnn4n6n7n4n6n7nn