#include <stdio.h>
#include <stdlib.h>
#include<malloc.h>
#define INF 32767
#define MAXV 100
typedef char InfoType;
typedef struct ANode
{
int adjvex;
struct ANode *nextrac;
int weight;
}ArcNode;
typedef struct Vnode
{
InfoType info;
int count;
ArcNode *firstarc;
}VNode;
typedef struct
{
VNode adjlist[MAXV];
int n,e;
}AdjGraph;
void CreateAdj(AdjGraph *&G,int A[MAXV][MAXV],int n,int e)
{
int i,j;
ArcNode *p;
G=(AdjGraph *)malloc (sizeof (AdjGraph));
for(i=0;i<n;i++)
{
for(j=n-1;j>=0;j--)
if(A[i][j]!=0 && A[i][j]!=INF)
{
p=(ArcNode*)malloc (sizeof(ArcNode));
p->adjvex=j;
p->weight=A[i][j];
p->nextrac=G->adjlist[i].firstarc;
G->adjlist[i].firstarc=p;
}
G->n=n;G->e=n;
}
}
void DispAdj(AdjGraph *G) //Êä³ö
{
ArcNode *p;
for(int i=0;i<G->n;i++)
{
p=G->adjlist[i].firstarc;
printf("%3d:",i);
while(p!=NULL)
{
printf("%3d[%d]->",p->adjvex,p->weight);
p=p->nextrac;
}
printf("¡Ä\n");
}
}
/*void BFS(AdjGraph *G,int v)
{
int w,i;ArcNode *p;
SqQueue *qu;
InitQueue(qu);
int visited[MAXV];
for(i=0;i<G->n;i++) visited[i]=0;
printf("%2d",v);
visited[v]=1;
enQueue(qu,v);
while(!QueueEmpty(qu))
{
deQueue(qu,w);
p=G->adjlist[w].firstarc;
while(p!=NULL)
{
if(visited[p->adjvex]==0)
{
printf("%2d",p->adjvex);
visited[p->adjvex]=1;
enQueue(qu,p->adjvex);
}
p=p->nextrac;
}
}
printf("\n");
}*/
int main()
{
AdjGraph *G;
int A[MAXV][MAXV]={
{0,1,0,1,1},{1,0,1,1,0},
{0,1,0,1,1},{1,1,1,0,1},{1,0,1,1,0}
};
int n,e;
//int n=5,e=8;
scanf("%d",&n);
scanf("%d",&e);
CreateAdj(G,A,n,e);
printf("ͼGµÄÁÚ½Ó±í£º\n"); DispAdj(G);
// BFS(G,0);
return 1;
}