luogu P3183 [HAOI2016]食物链
Posted ZlycerQan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了luogu P3183 [HAOI2016]食物链相关的知识,希望对你有一定的参考价值。
二次联通门 : luogu P3183 [HAOI2016]食物链
/* luogu P3183 [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[]) {;}
以上是关于luogu P3183 [HAOI2016]食物链的主要内容,如果未能解决你的问题,请参考以下文章