BZOJ 4562: [Haoi2016]食物链
二次联通门 : BZOJ 4562: [Haoi2016]食物链
二次联通门 : luogu P3183 [HAOI2016]食物链
/* BZOJ 4562: [Haoi2016]食物链 记忆化搜索 */ #include <cstdio> #include <iostream> const int BUF = 12312312; char Buf[BUF], *buf = Buf; inline void read (int &now) { for (now = 0; !isdigit (*buf); ++ buf); for (; isdigit (*buf); now = now * 10 + *buf - '0', ++ buf); } #define Max 200004 int N, M, S, T, Answer; struct E { E *n; int v; }; E *list[Max], poor[Max << 2], *Ta = poor; int _in[Max], _out[Max]; int c[Max]; int Dfs (int now) { if (_out[now] == 0) return 1; if (c[now]) return c[now]; int res = 0; for (E *e = list[now]; e; e = e->n) res += Dfs (e->v); c[now] = res; return res; } int Main () { fread (buf, 1, BUF, stdin); int x, y; read (N), read (M); register int i, j; for (i = 1; i <= M; ++ i) { read (x), read (y); ++ Ta, Ta->n = list[x], list[x] = Ta, Ta->v = y; ++ _in[y], ++ _out[x]; } for (i = 1; i <= M; ++ i) if (_in[i] == 0 && _out[i]) Answer += Dfs (i); printf ("%d", Answer); return 0; } int ZlycerQan = Main (); int main (int argc, char *argv[]) {;}
myj 吊打我Orz,xxy 捆起来打我Orz,myl 文化课上天Orz, lrh 姿势水平敲高Orz, hkd 特别胖Orz%%%,cys 智商感人Orz,syl zz专业Orz,我没有学上, 我们未来一片光明