ProgramAlgTrain/20240908/P2016/P2016.cpp

46 lines
721 B
C++
Raw Normal View History

2024-09-15 09:35:54 +00:00
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
const int MAX_N = 1.5e5+5;
int n;
std::vector<int> v[MAX_N];
int dp[MAX_N][2];
void dfs(const int n,const int f){
for(auto &i:v[n]){
if(i!=f)dfs(i, n);
else continue;
dp[n][1]+=std::min(dp[i][0],dp[i][1]);
dp[n][0]+=dp[i][1];
}
}
int main(){
std::cin>>n;
for(int _i=0;_i<n;_i++){
dp[_i][1]=1;
int i,k;
std::cin>>i>>k;
for(int j=1;j<=k;j++){
int r;
std::cin>>r;
v[i].push_back(r);
v[r].push_back(i);
}
}
dfs(0,-1);
std::cout<<std::min(dp[0][1],dp[0][0]);
}
/*
4
0 1 1
1 2 2 3
2 0
3 0
*/