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[]) {;}

 

转载于:https://www.cnblogs.com/ZlycerQan/p/7469591.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值