比赛 NOIP模拟赛by mzx Day2 评测结果 AAAAAAAAAA
题目名称 森林大礼包 最终得分 100
用户昵称 KZNS 运行时间 1.117 s
代码语言 C++ 内存使用 1.73 MiB
提交时间 2016-10-20 18:53:06
显示代码纯文本
//KZNS
#include <cstdio>
#include <vector>
using namespace std;
#define Nmax 100003
#define MD 1000000007
int als[Nmax] = {0};
int N;
vector<int> gp[Nmax];
bool pud[Nmax] = {false};
int init() {
    scanf("%d", &N);
    int M;
    int u;
    for (int i = 1; i <= N; i++) {
        scanf("%d", &M);
        for (int j = 0; j < M; j++) {
            scanf("%d", &u);
            gp[i].push_back(u);
        }
    }
    als[0] = 1;
    pud[0] = true;
}
void DFS(int x) {
    pud[x] = true;
    int t;
    for (int i = 0; i < gp[x].size(); i++) {
        t = gp[x][i];
        if (!pud[t])
            DFS(t);
        als[x] = (als[x] + als[t]) % MD;
    }
}
int main() {
    freopen("three_squirrels.in", "r", stdin);
    freopen("three_squirrels.out", "w", stdout);
    init();
    DFS(N);
    printf("%d\n", als[N]);
    return 0;
}
//UBWH