<USACO09DEC>过路费Cow Toll Pathsの思路

啊好气 在洛谷上A了之后 隔壁jzojwa

迷茫了很久.发现那题要文件输入输出

生气

肥肠不爽

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 int n[255][255],cc[255][255],w[255];
 7 int N,m,k,u,v,l,s,t;
 8 struct node{
 9     int id,w;
10 }c[255];
11 void floyd()
12 {
13     int p,o,i,j;
14     for(i=1;i<=N;i++)
15          cc[i][i]=c[i].w;
16     for(p=1;p<=N;p++)
17     {
18         o=c[p].id;
19          for(i=1;i<=N;i++)   
20                for(j=1;j<=N;j++)   
21             {
22                 if(n[i][j]>n[i][o]+n[o][j])n[i][j]=n[j][i]=n[i][o]+n[o][j];//单纯的多源最短路 
23                 if(cc[i][j]>n[i][j]+max(c[p].w,max(w[i],w[j])))cc[i][j]=cc[j][i]=n[i][j]+max(c[p].w,max(w[i],w[j]));//带上点权.! 
24             }
25     }
26 }
27 bool cmp(node a,node b){return a.w<b.w;}
28 int main()
29 {
30     int i,j;
31     //freopen("toll.in","r",stdin);
32     //freopen("toll.out","w",stdout); 
33     scanf("%d%d%d",&N,&m,&k);
34     memset(n,5,sizeof(n));
35     memset(cc,5,sizeof(cc));
36     for(i=1;i<=N;i++)n[i][i]=0;
37     for(i=1;i<=N;i++)scanf("%d",&c[i].w),c[i].id=i,w[i]=c[i].w;
38     sort(c+1,c+N+1,cmp);//排序.! 
39     
40     for(i=1;i<=m;i++)
41     {
42         scanf("%d%d%d",&u,&v,&l);
43          n[v][u]=n[u][v]=min(n[u][v],l);
44     }
45     floyd();
46     for(i=1;i<=k;i++)
47     {
48         scanf("%d%d",&s,&t);
49         printf("%d\n",cc[s][t]);
50     }
51 return 0;
52 }

猜你喜欢

转载自www.cnblogs.com/pile8852/p/9280502.html