【模板】图

· · 个人记录

#define go(G, u) for(int i = G.head[u], v = G.to[i]; i; i = G.nxt[i], v = G.to[i])
struct Graph {
    int to[M], nxt[M], head[N], cnt;
    inline void add(int u, int v) {
        to[++cnt] = v;
        nxt[cnt] = head[u];
        head[u] = cnt;
    }
    inline void init() {
          fu(i, 1, n) head[i] = 0;
          cnt = 0;
    }
} G;