假設無向圖g採用鄰接矩陣儲存,編寫乙個演算法輸出鄰接表。
description
第一行為乙個
整數n,表示頂點的個數(頂點
編號為0到n-1)
,接下來是為乙個n*n大小的
整數矩陣,表示圖的鄰接關係。數字為0表示不鄰接,
1表示鄰接。
input
輸出圖g的鄰接表。
第一行表示頂點0可直接到達的
頂點編號。其他行定義相同。
output 123
4565
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
sample input 123
45
134
023134
0124
023sample output
#include
#include
#include
using namespace std;
struct point
;int main()
return 0;
}void res(int total)
else
q=p;
}//想了好久終於出來了。。。}}
for(i=0;i
cout
}
鄰接矩陣與鄰接表
鄰接矩陣表示圖 public class graph private int vertexnum private int edgenum private int g 鄰接矩陣 public graph int vertexnum public void insertedge edge edge pu...
鄰接矩陣 鄰接鍊錶 轉換
include include include graph.h include using namespace std typedef int infotype define maxv 100 最大頂點個數 define inf 32767 inf表示 以下定義鄰接矩陣型別 typedef stru...
鄰接矩陣 鄰接表的遍歷方法
根據大話資料結構整理 輸入 鄰接矩陣vmatrix 鄰接表vlist,頂點表vnode 輸出 遍歷vva元素 include include include using namespace std define inf 5000 鄰接矩陣深度優先遍歷 void dfsmatrix vector vv...