|
V0
|
V1
|
V2
|
V3
|
V4
|
V5
|
V0
|
0
|
1
|
1
|
0
|
0
|
0
|
V1
|
1
|
0
|
1
|
1
|
1
|
0
|
V2
|
1
|
1
|
0
|
0
|
1
|
0
|
V3
|
0
|
1
|
0
|
0
|
1
|
1
|
V4
|
0
|
1
|
1
|
1
|
0
|
1
|
V5
|
0
|
0
|
0
|
1
|
1
|
0
|
|
V0
|
V1
|
V2
|
V3
|
V4
|
V5
|
V0
|
INF
|
1
|
4
|
INF
|
INF
|
INF
|
V1
|
1
|
INF
|
2
|
7
|
5
|
INF
|
V2
|
4
|
2
|
INF
|
INF
|
1
|
INF
|
V3
|
INF
|
7
|
INF
|
INF
|
3
|
2
|
V4
|
INF
|
5
|
1
|
3
|
INF
|
6
|
V5
|
INF
|
INF
|
INF
|
2
|
6
|
INF
|
- #define M 100
- struct ArcNode{
- int adjvex;
- ArcNode *nextarc;
- };
- struct VNode{
- int data;
- ArcNode *head1;
- ArcNode *head2;
- };
- struct LGraph{
- VNode vertexs[M];
- int vexnum,arcnum;
- };
- LGraph lg;
- void createLG(){
- int i=0;
- ArcNode *pi;
- int v1,v2;
- lg.vexnum=lg.arcnum=0;
- scanf("%d%d",&lg.vexnum,&lg.arcnum);
- for(i=0;i<lg.vexnum;i++){
- lg.vertexs[i].head1=lg.vertexs[i].head2=NULL;
- }
- for(i=0;i<arcnum;i++){
- scanf("%d%d",&v1,&v2);
- v1--;v2--;//下标从零开始
- pi=new ArcNode;
- pi->adjvex=v2;
- pi->nextarc=lg.vertexs[v1].head1;
- lg.vertexs[v1].head1=pi;
- pi=new ArcNode;
- pi->adjvex=v1;
- pi->nextarc=lg.vertexs[v2].head2;
- lg.vertexs[v2].head2=pi;
- }
- }
- #define M 100
- struct ArcNode{
- int adjvex;
- ArcNode *nextarc;
- };
- struct VNode{
- int data;
- ArcNode *head;
- };
- struct LGraph{
- VNode vertexs[M];
- int vexnum,arcnum;
- };
- LGraph lg;
- void createLG(){
- int i=0;
- ArcNode *pi;
- int v1,v2;
- lg.vexnum=lg.arcnum=0;
- scanf("%d%d",&lg.vexnum,&lg.arcnum);
- for(i=0;i<lg.vexnum;i++){
- lg.vertexs[i].head=NULL;
- }
- for(i=0;i<arcnum;i++){
- scanf("%d%d",&v1,&v2);
- v1--;v2--;//下标从零开始
- pi=new ArcNode;
- pi->adjvex=v2;
- pi->nextarc=lg.vertexs[v1].head;
- lg.vertexs[v1].head=pi;
- pi=new ArcNode;
- pi->adjvex=v1;
- pi->nextarc=lg.vertexs[v2].head;
- lg.vertexs[v2].head=pi;
- }
- }