#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 2008;
vector<int> arr[maxn];
int f[maxn][2],n,vis[maxn];
void dfs(int cur) {
f[cur][0] = 0;
f[cur][1] = 1;
for (int i = 0; i < arr[cur].size(); i++) {
int v = arr[cur][i];
dfs(v);
f[cur][0] += f[v][1];
f[cur][1] += min(f[v][0], f[v][1]);
}
}
int main()
{
while (cin >> n) {
memset(f, 0, sizeof(f));
memset(vis, 0, sizeof(vis));
for (int i = 0; i <= n; i++)arr[i].clear();
int x, y,cnt;
for (int i = 1; i <= n; i++) {
scanf("%d:(%d)", &x, &cnt);
for (int j = 0; j < cnt; j++) {
scanf(" %d", &y);
arr[x].push_back(y);
vis[y] = 1;
}
}
int root = 0;
for (int i = 0; i < n; i++) {
if (!vis[i])root = i;
}
dfs(root);
cout << min(f[root][0], f[root][1]) << endl;
}
return 0;
}
uva1292
最新推荐文章于 2024-11-09 20:38:27 发布