Save edge;
For the list of neighboring tables implemented by pointers:
Struct edge {int from, next, to, W;} e [maxn]; int head [maxn], TOT = 0; // head is initialized to-1; void add (int x, int y, int Z) {e [++ tot]. from = x; // header node E [tot]. to = y; // connect to the next node E [tot]. W = z; // Edge Weight E [tot]. next = head [X]; // connection pointer head [x] = tot; // pointer pointing to tot, you can use head [x] As the subscript, using e}
For vector:
#include <cstdio>#include <vector>struct edge{int v,w;edge(int _v,int _w){v=_v;w=_w;}};vector <edge> g[maxn];void add(int x,int y,int z){g[x].push_back(edge(y,z));}
Specific call:
For example, we need to find all the edges connected by u in spfa;
Adjacent table:
Void use (int x) {int u = x; // X indicates the header node; For (INT I = head [u]; I! =-1; I = E [I]. Next) {v = E [I]. ;}}
Vector:
void use(int x){int ans=g[x].size();for(int i=0;i<ans;i++){int v=g[x][i].v;} }
Note that the vector is saved from 0;
In general, vector is relatively easy to use, but it is too weak> <, sometimes STL is not used, so be careful ~~
Using an adjacent table or vector to implement edge storage and calling the [TEMPLATE]