记录编号 |
602684 |
评测结果 |
A |
题目名称 |
2997.[POJ 1463]战略游戏 |
最终得分 |
100 |
用户昵称 |
汐汐很希希 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.108 s |
提交时间 |
2025-07-05 14:48:37 |
内存使用 |
4.09 MiB |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1510;
int n=1,f[N][2];
vector<int> g[N];
void dp(int x,int fa)
{
f[x][0]=0,f[x][1]=1;
for(int i=0;i<g[x].size();i++)
{
int y=g[x][i];
if(y==fa) continue;
dp(y,x);
f[x][0]+=f[y][1];
f[x][1]+=min(f[y][0],f[y][1]);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
freopen("strategic.in","r",stdin);
freopen("strategic.out","w",stdout);
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++) g[i].clear();
memset(f,0,sizeof(f));
for(int i=0;i<n;i++){
int x,y;
scanf("%d:(%d)",&x,&y);
for(int j=0;j<y;j++){
int ch;
scanf("%d",&ch);
g[x].push_back(ch);
g[ch].push_back(x);
}
}
dp(0,-1);
int ans=min(f[0][0],f[0][1]);
cout<<ans<<endl;
}
return 0;
}