84pts WA on #1 求调
查看原帖
84pts WA on #1 求调
1029575
Alg_orithm楼主2025/1/20 11:01
#include<bits/stdc++.h>
using namespace std;
const int N=1510;
vector<int> v[N];
int f[N][2];
bool r[N];
void dfs(int k)
{
	f[k][1]=1;
	for(int i=0;i<v[k].size();i++)
	{
		int son=v[k][i];
		dfs(son);
		f[k][0]+=f[son][1];
		f[k][1]+=min(f[son][0],f[son][1]);
	}
}
int main()
{
	int n,i,j,k,x,root;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&j,&k);
		while(k--)
		{
			scanf("%d",&x);
			v[j].push_back(x);
		}
	}
	dfs(0);
	cout<<min(f[root][0],f[root][1]);
	return 0;
}
2025/1/20 11:01
加载中...