1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include<bits/stdc++.h> using namespace std; inline int read(){int res=0,f=1;char ch=getchar();while(ch<'0'ch>'9'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar();return res*f;} inline void write(int x){if(x<0) putchar('-'),x=-x;if(x<10) putchar(x+'0');else write(x/10),putchar(x%10+'0');} int n,m,q,f[255][255],ans[255][255],g[255]; struct node{int v,id;}a[255]; inline int cmp(node x,node y){return x.v<y.v;} int main(){ n=read(),m=read(),q=read(); for(int i=1;i<=n;i++) a[i].v=read(),a[i].id=i; memset(f,63,sizeof(f)); memset(ans,63,sizeof(ans)); for(int i=1;i<=n;i++) f[i][i]=ans[i][i]=a[i].v; for(int x,y,z,i=1;i<=m;i++){ x=read(),y=read(),z=read(); f[x][y]=f[y][x]=min(f[x][y],z); } sort(a+1,a+n+1,cmp); for(int i=1;i<=n;i++) g[a[i].id]=i; #define mid a[k].id #define val a[k].v for(int k=1;k<=n;k++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ f[i][j]=min(f[i][j],f[i][mid]+f[mid][j]); ans[i][j]=min(ans[i][j],f[i][j]+max(val,max(a[g[i]].v,a[g[j]].v))); } } } #undef mid #undef val for(int x,y,i=1;i<=q;i++){ x=read(),y=read(); write(ans[x][y]),putchar('\n'); } return 0; }
|