标签:style blog io color os for sp div log
Dp 适合点少的稠密图。
//蒟蒻 最短路 #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #include<cmath> #include<queue> using namespace std; int main() { int n,m,edge[110][110]; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) edge[i][j] = 999999999; for(int i=1;i<=m;i++) { int x,y,z; scanf("%d%d%d",&x,&y,&z); edge[x][y] = z; } for(int i=1;i<=n;i++) edge[i][i] = 0; for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(edge[i][j]>edge[i][k]+edge[k][j]) edge[i][j]=edge[i][k]+edge[k][j]; } int s,t; scanf("%d%d",&s,&t); cout<<edge[s][t]<<endl; return 0; }
标签:style blog io color os for sp div log
原文地址:http://www.cnblogs.com/coutendl/p/4079067.html