链式向前星--邻接表存储图
来源:互联网 发布:易语言 crm 源码下载 编辑:程序博客网 时间:2024/04/28 17:54
#include<stdio.h>#include<string.h>#define maxn 202struct ss{ int v,w; int next;}edge[maxn];int top;int head[maxn];void add(int u,int v,int w){ edge[top].v=v; edge[top].w=w; edge[top].next=head[u]; head[u]=top++;}void print(int i){ for(int u=head[i];u!=0;u=edge[u].next) printf("%d %d %d \n",i,edge[u].v,edge[u].w);}int main(){ //freopen("Input.txt","r",stdin); int n,m; while(~scanf("%d%d",&n,&m)) { memset(head,0,sizeof(head)); top=1; int a,b,c; while(m--) { scanf("%d%d%d",&a,&b,&c); add(a,b,c); } scanf("%d",&m); while(m--) { scanf("%d",&a); print(a); } } return 0;}