图的一些板子

· · 个人记录

链式前向星

struct graph{
    struct node{
        ll from, to, dis, next;
    }edge[M << 1];
    ll t, head[N];
    inline void clear(){
        memset(head, 0, sizeof(head));
        t = 0;
    }
    inline void add_edge(ll u, ll v, ll w){
        edge[++t] = (node){u, v, w, head[u]};
        head[u] = t;
    }
}G;