( ̄▽ ̄) "
//Dijkstra algorithm;//This topic constructs the adjacency matrix when has the pit (reads first the edge after reads into the point), but also has the heavy edge;#include <iostream>#include<cstdio>using namespacestd;Const intinf=10e7;Const intmaxn= .;intK,minn;intCOST[MAXN][MAXN];intLOWCOST[MAXN];BOOLVIS[MAXN];voidDij (intNintstart) { for(intI=1; i<=n;i++) {Lowcost[i]=inf;vis[i]=0; } Lowcost[start]=0; for(intI=1; i<=n;i++) {k=-1, minn=INF; for(intI=1; i<=n;i++) { if(!vis[i]&&lowcost[i]<Minn) {Minn=lowcost[i];k=i;} } if(k==-1) Break; VIS[K]=1; for(intI=1; i<=n;i++) { if(!vis[i]&&cost[k][i]>=0&&lowcost[k]+cost[k][i]<Lowcost[i]) {Lowcost[i]=lowcost[k]+Cost[k][i]; } } }}intMain () {intT,n,a,b,c; while(SCANF ("%d%d", &t,&n)! =EOF) { for(intI=1; i<=n;i++) { for(intj=1; j<=n;j++) { if(I==J) cost[i][j]=0; Elsecost[i][j]=INF; } } for(intI=1; i<=t;i++) {scanf ("%d%d%d",&a,&b,&c); if(c<Cost[a][b]) {Cost[a][b]=c; cost[b][a]=C;} } dij (N,n); printf ("%d\n", lowcost[1]); } return 0;}
POJ 2387 Til The Cows Come Home (dij+ adjacency matrix)