Descriptionair Bovinia is planning to connect the N-Farms (1 <= n <=) that the cows live on. As with any airline, K of these farms (1 <= k <=, K <= N) has been selected as hubs. The farms is conveniently numbered 1..N, with farms 1..K being the hubs. Currently there is M (1 <= m <=) one-way flights connecting these farms. Flight I travels from farm U_i to farm v_i, and costs d_i dollars (1 <= d_i <= 1,000,000). The airline recently received a request for Q (1 <= Q <=) one-way trips. The ith trip was from farm A_i to farm b_i. In order to get from a_i to B_i, the "trip" include any sequence of direct flights (possibly even visiting the same farm multiple times), but it must include at least one hub (which may or May is not being be is the start or the destination). This requirement could result in there being no valid route from A_i to B_i. For all other trips requests, however, your goal is to help Air Bovinia determine the minimum cost of A valid route.
input* line 1:four integers:n, M, K, and Q. * Lines 2..1+m:line i+1 contains U_i, v_i, and d_i for Flight I. * Lines M.. 1+m+q:line 1+m+i describes the ith trip in terms of a_i and b_i
output* line 1:the number of trips (out of the Q) for which a valid route is possible. * Line 2:the sum, on all trips to which a valid route is possible, of the minimum possible route cost.
Sample Input3 3 1 3
3 1 10
1 3 10
1 2 7
3 2
2 3
1 2
INPUT Details:there is three farms (numbered 1..3); Farm 1 is a hub. There is a $ flight from farm 3 to farm 1, and so on. We wish to look for trips from farm 3 to farm 2, from 2->3, and from 1->2.
Sample Output2
24
OUTPUT details:the trips from 3->2 have only one possible route, the cost of 10+7. The trip from 2->3 have no valid route, since there is no flight leaving Farm 2. The trip from 1->2 have only one valid route again, of which cost 7.
Contest has ended. No further submissions allowed.Test instructions is n points m bar has direction, ask for the shortest circuit between 22, requires the path must be numbered 1~k at least one point to build the diagram hierarchy, the lower layer to copy the above, and then 1~k point from the upper level of the edge of the right side of 0, run Floyd I really bi the dog opened a 200* An array of 200 re is constantly criticized by the yellow giant
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5 #defineLL Long Long6 #defineINF 1000000000007 using namespacestd;8 intN,m,k,q,tot;9 Long Longans;Ten Long Longdist[410][410]; One inline LL read () A { -LL x=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} the while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} - returnx*F; - } - intMain () + { - for(intI=1; i<= -; i++) for(intj=1; j<= -; j + +) dist[i][j]=inf; +N=read (); M=read (); K=read (); q=read (); A for(intI=1; i<=m;i++) at { - intX=read (), y=read (); -dist[x][y]=dist[x+n][y+n]=read (); - } - for(intI=1; i<=k;i++) dist[i][n+i]=0; - for(intL=1; l<=2*n;l++) in for(intI=1; i<=2*n;i++) - for(intj=1; j<=2*n;j++) to if(dist[i][j]>dist[i][l]+Dist[l][j]) +dist[i][j]=dist[i][l]+Dist[l][j]; - for(intI=1; i<=q;i++) the { * intX=read (), y=read (); $ if(DIST[X][N+Y]>1E10)Continue;Panax Notoginsengtot++;ans+=dist[x][n+y]; - } theprintf"%d\n%lld", Tot,ans); +}bzoj4097
bzoj4097 [Usaco2013 dec]vacation planning