Graph theory plus edge algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.