比赛 |
2024国庆练习1 |
评测结果 |
AAAAAAAAAA |
题目名称 |
森林大礼包 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
0.389 s |
代码语言 |
C++ |
内存使用 |
6.99 MiB |
提交时间 |
2024-10-04 17:17:09 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 1e5+10;
const ll mod = 1e9+7;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n;
ll f[N];
int nx[N][12],l[N];
ll dfs(int x){
if(f[x] != -1)return f[x];
ll ans = 0;
for(int i = 1;i <= l[x];i++)(ans += dfs(nx[x][i])) %= mod;
return f[x] = ans;
}
int main(){
freopen("three_squirrels.in","r",stdin);
freopen("three_squirrels.out","w",stdout);
n = read();
memset(f,-1,sizeof f);
f[0] = 1;
for(int i = 1;i <= n;i++){
l[i] = read();
for(int j = 1;j <= l[i];j++)nx[i][j] = read();
}
printf("%lld\n",dfs(n));
return 0;
}