码迷,mamicode.com
首页 > 其他好文 > 详细

MZOJ 1127 && LuoGu P2016 战略游戏

时间:2019-01-21 19:19:39      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:mes   传送门   blank   namespace   \n   href   战略   void   data-   

MZOJ 1127 && LuoGu P2016 战略游戏   [传送门]

#include<bits/stdc++.h>
#define maxn 100000
using namespace std;

int k=0,head[maxn];
int f[maxn][2];
int ans=0;

struct node{
    int v,nxt;
}e[maxn<<1];

void adde(int u,int v){
    e[k].v=v;
    e[k].nxt=head[u];
    head[u]=k++;
} 

void dp(int u,int fa){
    f[u][0]=0;f[u][1]=1;
    for(int i=head[u];~i;i=e[i].nxt){
        int v=e[i].v;
        if (v==fa) continue;
        dp(v,u);
        f[u][0]+=f[v][1];
        f[u][1]+=min(f[v][0],f[v][1]);
    }
}

void init(){
    freopen("soldier.in.txt","r",stdin);
    //freopen("solider.txt","w",stdout);
}

void readdata(){
    int n,x,y,m;
    while(scanf("%d",&n)!=EOF){
        memset(head,-1,sizeof(head));
        for(int i=1;i<=n;i++){
            scanf("%d%d",&x,&m);
            for(int j=1;j<=m;j++){
                scanf("%d",&y);
                adde(x,y);
                adde(y,x);
            }
        }
        dp(0,-1);
        printf("%d\n",min(f[0][1],f[0][0]));
    }
}

int main(){
    //init();
    readdata();
    return 0;
}

 

MZOJ 1127 && LuoGu P2016 战略游戏

标签:mes   传送门   blank   namespace   \n   href   战略   void   data-   

原文地址:https://www.cnblogs.com/quietus/p/10300017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!