#include<stdio.h>
#include<stdlib.h>
struct node{
int x,y,s;
struct node *r,*d;
node(){
x=y=s=0;
r=d=NULL;
}
};
struct node *l_a[1001],*c_a[1001];
struct node *p,*q;
int m,n;
int insert(int u,int v,int w){
int i,j,k,l;
p=l_a[u];
while(p->r!=NULL)p=p->r;
q=new node;
q->x=u;q->y=v;q->s=w;
q->r=NULL;q->d=NULL;
p->r=q;
p=c_a[v];
while(p->d!=NULL)p=p->d;
p->d=q;
}
int out(){
int i,j,k,l;
for (i=1;i<=n;i++){
printf("\n%d->",i);
while(l_a[i]->r!=NULL){
l_a[i]=l_a[i]->r;
printf("%d %d\n",l_a[i]->y,l_a[i]->s);
}
printf("\n->%d",i);
while(c_a[i]->d!=NULL){
c_a[i]=c_a[i]->d;
printf("%d %d\n",c_a[i]->x,c_a[i]->s);
}
}
return 0;
}
int main(){
int i,j,k,l;
int u,v,w;
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++){
l_a[i]=new node;
c_a[i]=new node;
}
for (i=1;i<=m;i++){
scanf("%d%d%d",&u,&v,&w);
insert(u,v,w);
}
out();
return 0;
}
十字链表
最新推荐文章于 2022-08-23 16:21:51 发布