题解:

简单灌水

然后统计一下

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=20005;
int ne[N],num,fi[N],n,k,m,x,y,ans,zz[N],f[N],sum[N],x1[N];
void jb(int x,int y)
{
    ne[++num]=fi[x];
    fi[x]=num;
    zz[num]=y;
}
void dfs(int x)
{
    f[x]=1;
    sum[x]++;
    for (int i=fi[x];i;i=ne[i])
     if (!f[zz[i]])dfs(zz[i]);
}
int main()
{
    scanf("%d%d%d",&k,&n,&m);
    for (int i=1;i<=k;i++)scanf("%d",&x1[i]);
    while (m--)
     {
         scanf("%d%d",&x,&y);
         jb(x,y);
     }
    for (int i=1;i<=k;i++)
     {
         memset(f,0,sizeof f);
         dfs(x1[i]);
     } 
    for (int i=1;i<=n;i++)
     if (sum[i]==k)ans++;
    printf("%d",ans);  
    return 0; 
}

 

posted on 2018-02-23 15:45  宣毅鸣  阅读(76)  评论(0编辑  收藏  举报