Many graph theory algorithms have a function
struct Edge { int to; int W; int next;} Edge[n * 2];int Cnt_edge = 0;void add_edge (int from, int. to, Int. W) { edge[cnt_edge].to = to; EDGE[CNT_EDGE].W = W; Edge[cnt_edge].next = Head[from]; Head[from] = cnt_edge++;} Memset (Head,-1, sizeof head);
I've been wrestling with the meaning of this function for a long time ...
In fact, a diagram is stored with an adjacency table.
Cnt_edge is to give each side a label, starting from 0.
The edge[i].to represents the point at which the edge of the section I is pointing, and Edge[i].next represents the ordinal of the next edge of the I-bar.
Head[from] Indicates the ordinal of an edge that is the initial node from the first point.
Example (casually painted = =#):
Presence Edge 1,3 1,4 2,5 2,6 4,3 5, 36 edges
After calling the function Add_edge in turn, you can get
edge[0].to=3; Edge[0].next=-1; head[1]=0;
edge[1].to=4; edge[1].next=0; Head[1]=1;
edge[2].to=5; Edge[2].next=-1; head[2]=2;
edge[3].to=6; edge[3].next=5; head[2]=3;
edge[4].to=3; Edge[4].next=-1; head[4]=4;
edge[5].to=3; Edge[5].next=-1; head[5]=5;
A graph means:
Meow. How do you draw the direction of the arrows?
Graph theory plus edge algorithm