这是周赛1的c题我被自己坑了,数组想都没想就开100,freopen没有去掉。就这样我re了两次。下次一定要注意。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=1e9;
int map[1005][1005];
int vis[1005],dis[1005];
int n;
void dijkstra(int from,int to,int n)
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)dis[i]=map[from][i];
vis[from]=1;
dis[from]=0;
for(int i=0;i<n;i++){
int x,MIN=INF;
for(int y=1;y<=n;y++){
if(!vis[y]&&dis[y]<MIN)
MIN=dis[x=y];
}
vis[x]=1;
for(int y=1;y<=n;y++){
dis[y]=min(dis[y],dis[x]+map[x][y]);
}
}
}
int main()
{
//freopen("in.txt","r",stdin);
int T;
scanf("%d%d",&T,&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
map[i][j]=INF;
for(int i=1;i<=n;i++)map[i][i]=0;
int from,to,length;
while(T--){
scanf("%d %d %d",&from,&to,&length);
if(length<map[from][to])
map[from][to]=map[to][from]=length;
}
dijkstra(n,1,n);
printf("%d\n",dis[1]);
return 0;
}