1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <vector>

using namespace std;

const int N = 110;

int n, c[N], deg[N];
vector<int> adj[N];

void top_sort(int u) {
  for (int v : adj[u]) {
    c[v] += c[u];
    --deg[v];
    if (deg[v] == 0) top_sort(v);
  }
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int k;
    cin >> k;
    while (k--) {
      int v;
      cin >> v;
      adj[i].push_back(v);
      ++deg[v];
    }
  }

  c[1] = 1;
  top_sort(1);

  cout << c[n]+1 << endl;

  return 0;
}