Link List Simulation const int N = 100010, M = N * 2; int h[N], e[M], ne[M], w[M], idx; void add(int a, int b, int c) { // add a->b wight=c e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++; } This code can use for storage graph or tree.