Title Description
Kudo ' s real name is not Kudo. Her name was Kudryavka Anatolyevna Strugatskia, and Kudo was only her nickname.
Now, she's facing an emergency in her hometown:
Her mother is developing a new kind of spacecraft. This plan costs enormous and finally failed. What's more, because of the failed project,
The government doesn ' t has enough resource take measure to the rising sea levels caused by global warming, leads to an ISL And flooded by the sea.
Dissatisfied with her mother's spacecraft and the government, civil war had broken out.
The foe wants to arrest the spacecraft project ' s participants and the ' chief criminal ' –kudo ' mother–doctor T ' s family .
At the beginning of the war, all the cities is occupied by the foe. But as time goes by, the cities recaptured one by one.
To prevent from the foe's arrest and boost morale, Kudo and some other people has to distract from a city to another. Although they can use some other means to transport,
The most convenient are using the inter-city roads. Assuming the city as a node and an inter-city road as an edge, you can treat the map as a weighted directed multigraph. An inter-city road is available if both it endpoint is recaptured.
Here comes the problem.
Given the traffic map, and the recaptured situation, can-tell-kudo what's the shortest path from one city to another O Nly passing the recaptured cities?
Input
The input consists of several test cases.
The first line of input in each test case contains three integers N (0<n≤300), M (0<m≤100000) and Q (0<q≤100000), which represents the number of cities, the numbers of inter-city roads and the number of operations.
Each of the next M lines contains three integer x, Y and Z, represents there are an inter-city road starts from X, end up W ith y and the length is Z. You can assume that 0<z≤10000.
Each of the next Q lines contains the operations with the following format:
A) 0 X–means City X have just been recaptured.
b) 1 x Y–means asking the shortest path from X to Y is only passing the recaptured cities.
The last case was followed by a line containing three zeros.
Output
For each case, print the case number (1, 2 ...) first.
For each operation 0, if City X is already recaptured (that is,the same 0 x operation appears again), print "City x is ALR Eady recaptured. "
For each operation 1, if City x or Y are not recaptured yet, the print "City x or Y are not available." Otherwise if Kudo can go From City X to City y only passing the recaptured cities,
Print the shortest path ' s length; Otherwise print "No such path."
Your output format should imitate the sample output. Print a blank line after each test case.
Sample input
3 3 60 1 11 2 10 2 31 0 20 00 21 0 21 2 00 20 0 0
Sample output
Case 1:city 0 or 2 are not available.3no such path. City 2 is already recaptured.
1 /*2 problem3 number of input vertices n, number of paths m, and number of operations Q4 if the operand is 0,x if it is not retracted, the output city%d is already recaptured.5 if the operand is 1,x and y if there is one that has not been retracted, the output city X or Y are not available.6 If there is a shortest path output shortest path, there is no path output no such path.7 8 Thinking of solving problems9 since the number of queries can be many and may be repeated and is the shortest of any two points, so each time you join a point Floyd, output the corresponding results. Ten */ One#include <cstdio> A#include <cstring> - Const intinf=99999999; - intn,m,q; the inte[ -][ -],book[ -]; - voidFloydintx) { - inti,j; - for(i=0; i<n;i++){ + for(j=0; j<n;j++){ - if(E[i][j] > E[i][x] +E[x][j]) { +E[I][J] = E[i][x] +E[x][j]; A } at } - } - /*For (i=0;i<n;i++) { - For (j=0;j<n;j++) { - printf ("%9d", E[i][j]); - } in printf ("\ n"); - }*/ to } + intMain () - { the intu,v,w,op,x,y,i,j,t=1; * while(SCANF ("%d%d%d", &n,&m,&q) = =3&& N+m+q! =0){ $printf"Case %d:\n", t++);Panax Notoginseng - for(i=0; i<n;i++){ the for(j=0; j<n;j++){ +E[I][J] = i==j?0: INF; A } the } + - while(m--){ $scanf"%d%d%d",&u,&v,&W); $ if(E[u][v] >W) -E[U][V] =W; - } the /*For (i=0;i<n;i++) { - For (j=0;j<n;j++) {Wuyi printf ("%9d", E[i][j]); the } - printf ("\ n"); Wu }*/ -memset (book,0,sizeof(book)); About while(q--){ $scanf"%d",&op); - if(OP = =0){ -scanf"%d",&x); - if(Book[x]) Aprintf"City %d is already recaptured.\n", x); + Else{ the Floyd (x); -book[x]=1; $ } the } the Else the { thescanf"%d%d",&x,&y); - if(Book[x] = =0|| Book[y] = =0){ inprintf"City %d or%d are not available.\n", x, y); the Continue; the } About if(E[x][y] <INF) theprintf"%d\n", E[x][y]); the Else theprintf"No such path.\n"); + } - } theprintf"\ n");Bayi } the return 0; the}
Emergency (Shandong Province first ACM program design real Problem +floyd algorithm variant)