模板:最小边支配集
C++#include <iostream>
#include <vector>
using namespace std;
const int N = 2e3 + 10;
int n,f[N][2];
bool vis[N];
vector <int> v[N];
inline void dfs(int x)
{
vis[x] = 1;
f[x][1] = 1,f[x][0] = 0;
for(int i = 0;i < v[x].size();i ++)
{
int g = v[x][i];
if (vis[g]) continue;
dfs(g);
f[x][0] += f[g][1];
f[x][1] += min(f[g][0],f[g][1]);
}
}
int main()
{
ios::sync_with_stdio(0);
cin >> n;
for(int i = 1;i <= n;i ++)
{
int x,y,z;
cin >> x >> y;
while (y --)
{
cin >> z;
v[x].push_back(z);
v[z].push_back(x);
}
}
dfs(1);
cout << min(f[1][0],f[1][1]) << endl;
return 0;
}