1.鄰接矩陣
g[N][N]二維陣列存盤,一般是稠密圖
注意資料范圍,點的數目N不能太大
2.鄰接表
一般用于稀疏圖
static int N= , M=2*N; static int h[]=new int[N]; static int e[]=new int[N]; //M 無向邊 ; N 有向邊 static int ne[]=new int[N];//M static int w[]=new int[N]; static int idx; static void add(int a,int b,int c){ e[idx]=b; w[idx]=c; ne[idx]=h[a]; h[a]=idx++; } Arrays.fill(h,-1);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/96532.html
標籤:其他
上一篇:847. 圖中點的層次
