DAY5 graph theory Shortest path, minimum spanning tree, topological sort, connected component, two-part graph.
In general, day5 this day of things to listen to not understand, ready to go back to the winter camp slowly understand.
The first thing to say is the adjacency matrix
If there are n points, a n*n two-dimensional array is established, and a marker on the J-bit of the I line indicates that I is connected with J.
The 2nd is the chain-forward star.
When listening to the day, listen very do not understand, and then listen to the big guy to talk about, the Internet search some information, but also understand some.
First build a _edge structure containing {to,next,val}, a head[] array, a counter tot
1 #define MX 100002struct _edge3{4 int to,next,val; 5 }EDGE[MX]; 6 int Head[mx],tot;
Code
Because the last step is to traverse from the back, so, at the time of construction, edge[tot].to points to V, the weight value W to Edge[].val, the edge[].next point to Head[u] (the last edge before the beginning), Head[u] point to Tot.
1 void Add (int u,int v,int w)2{3 edge[ tot].to=v; 4 Edge[tot].val=W; 5 edge[tot].next=Head[u]; 6 head[u]=tot++; 7 }
code (ADD)
Jilin Province 2017 year Winter camp DAY5