1 void toposort() { 2 int h = t = 0; 3 for (int i = 1; i <= n; i++) { 4 if (in[i] == 0) { 5 q[t++] = i; 6 } 7 } 8 while (h != t) { 9 k = q[h++]; 10 for (int i = h[k]; i; i = e[i].n) { 11 if (!--in[e[i].t]) { 12 q[t++] = e[i].t; 13 } 14 } 15 } 16 }