#include<iostream>
#include<cstring>
#define int long long
using namespace std;
const int N=4010,mod=1e9+7;
int a[N];
int e[N*N],ne[N*N],idx,h[N];
int st[N];
int ans;
int ans1[N];
int read()
{
int res=0,ch,flag=0;
if((ch=getchar())==‘-‘) //判断正负
flag=1;
else if(ch>=‘0‘&&ch<=‘9‘) //得到完整的数
res=ch-‘0‘;
while((ch=getchar())>=‘0‘&&ch<=‘9‘)
res=res*10+ch-‘0‘;
return flag?-res:res;
}
void add(int a,int b)
{
e[idx]=b;
ne[idx]=h[a];
h[a]=idx++;
}
int dp[N];
int res;
int dfs(int u,int fa)
{
if(dp[u]!=-1)
return dp[u];
if(st[u]==0)
{
res++;
dp[u]=1;
return dp[u];
}
int sum=0;
for(int i=h[u]; i!=-1; i=ne[i])
{
int j=e[i];
if(j==fa)
continue;
sum=(sum+(dfs(j,u)%mod))%mod;
}
dp[u]=sum;
return sum;
}
signed main()
{
memset(dp,-1,sizeof dp);
memset(h,-1,sizeof h);
int n=read(),l=read();
for(int i=1; i<=l; i++)
{
st[i]=1;
int k=read();
while(k--)
{
int a=i;
int b=read();
add(i,b);
}
}
ans=dfs(1,-1);
cout<<ans%mod<<" "<<res%mod<<endl;
}
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12665010.html
时间: 2024-11-07 21:38:26