//无向图 链式前向星
#include <bits/stdc++.h>
using namespace std;
const int maxv=100+5;
const int maxe=10000+5;
struct Edge{
int next,to,weight;
};
Edge edges[maxe];
int head[maxv],v,e,cnt;
void add(int u,int V,int dist)
{
edges[++cnt].next=head[u];
edges[cnt].to=V;
edges[cnt].weight=dist;
head[u]=cnt;
edges[++cnt].next=head[V];
edges[cnt].to=u;
edges[cnt].weight=dist;
head[V]=cnt;
}
int main()
{
cnt=0;
memset(head,0,sizeof(head));
scanf("%d%d",&v,&e);
for(int i=0;i<e;i++)
{
int V1,V2,dist;
scanf("%d%d%d",&V1,&V2,&dist);
add(V1,V2,dist);
}
int d;
while(scanf("%d",&d)==1&&d>0)
{
for(int i=head[d];i!=0;i=edges[i].next)
cout<<d<<"->"<<edges[i].to<<
链式前向星+dijkstra 使用链式前向星也可避免图中重边的问题
最新推荐文章于 2024-08-22 10:13:21 发布