邻接表

it2022-05-05  148

邻接表是通过枚举所有的顶点,和顶点所能到达的所有的边来表示图的。所以有一个顶点域和边域。

简单表述为

struct Edge

{

  int v, w, next;

}edge[MAXN];

int e, head[MAXN];

void init()

{

  e = 0;

  memset(head, -1, sizeof(head));

}

void add(int u, int v, int w)

{

  edge[e].v = v;

  edge[e].w = w;

  edge[e].next = head[u];

  head[u] = e++;

}

转载于:https://www.cnblogs.com/lihek/p/3216303.html

相关资源:图的实现:邻接表

最新回复(0)