比赛 NOIP模拟赛by mzx Day2 评测结果 AAAAAAAAAA
题目名称 森林大礼包 最终得分 100
用户昵称 Hzoi_Go灬Fire 运行时间 0.978 s
代码语言 C++ 内存使用 9.17 MiB
提交时间 2016-10-20 20:38:04
显示代码纯文本
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#define Inf 0x3f3f3f3f
#define LL unsigned long long
#define Begin freopen("three_squirrels.in","r",stdin);freopen("three_squirrels.out","w",stdout);
#define End fclose(stdin);fclose(stdout);
using namespace std;
const int maxn=150000;
const int mod=1e9+7;
struct Edge{
	int next,to,dis;
}e[maxn<<2];
int n;
LL hav[maxn],num[maxn];
int head[maxn],len;
bool vis[maxn];
void Insert(int x,int y){
	len++;e[len].to=y;e[len].next=head[x];head[x]=len;
} 
void Init();
int Dfs(int x){
	if(hav[x] && vis[x])return hav[x];
	if(x==0)return 1;
	for(int i=head[x];i;i=e[i].next){
		int j=e[i].to;
		hav[x]+=Dfs(j);
		hav[x]%=mod;
	}
	vis[x]=1;
	return hav[x];
}
int main(){
    Begin;
    Init();
    //system("pause");
    End;
    return 0;
}
void Init(){
	scanf("%d",&n);hav[0]=1;
	for(int i=1;i<=n;i++){
		scanf("%d",&num[i]);
		for(int j=1;j<=num[i];j++){
			int x;scanf("%d",&x);
			Insert(i,x);
		}
	}
	printf("%d\n",Dfs(n)%mod);
}
/*
5
2 0 3
2 0 0
3 0 0 0
4 0 0 0 0
5 0 0 1 0 0
*/