题目大意:
n个点,m条边,从1出发到n的最小边权和
边权>0解题思路:
SPFA模板
Accepted code:
#include#include #include #include #define inf 0x7fffffffusing namespace std;struct node { int y,c,next;}e[400001];bool v[2501];int n,m,cnt,last[2501],d[2501];inline void add(int x,int y,int z) { e[++cnt].y=y;e[cnt].c=z;e[cnt].next=last[x];last[x]=cnt; e[++cnt].y=x;e[cnt].c=z;e[cnt].next=last[y];last[y]=cnt;}void init() { scanf("%d%d",&n,&m); for (int i=1;i<=m;i++) { int x,y,z; scanf("%d%d%d",&x,&y,&z); add(x,y,z); } for (int i=1;i<=n;i++) d[i]=inf;}void SPFA() { queue q; q.push(1); v[1]=1; d[1]=0; while(q.size()) { int x=q.front(); q.pop(); v[x]=0; for (int i=last[x];i;i=e[i].next) { int y=e[i].y; if (d[x]+e[i].c