hdu6370(杭电多校第六场9)环套树

Werewolf

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1575    Accepted Submission(s): 439

Problem Description

"The Werewolves" is a popular card game among young people.In the basic game, there are 2 different groups: the werewolves and the villagers.
Each player will debate a player they think is a werewolf or not. 
Their words are like "Player x is a werewolf." or "Player x is a villager.".
What we know is :
1. Villager won't lie.
2. Werewolf may lie. 
Of cause we only consider those situations which obey the two rules above. 
It is guaranteed that input data exist at least one situation which obey the two rules above.
Now we can judge every player into 3 types :
1. A player which can only be villager among all situations, 
2. A player which can only be werewolf among all situations.
3. A player which can be villager among some situations, while can be werewolf in others situations.
You just need to print out the number of type-1 players and the number of type-2 players. 
No player will talk about himself.

Input

The first line of the input gives the number of test cases T.Then T test cases follow.
The first line of each test case contains an integer N,indicating the number of players.
Then follows N lines,i-th line contains an integer x and a string S,indicating the i-th players tell you,"Player x is a S."
limits:
1≤T≤10
1≤N≤100,000
1≤x≤N
S∈ {"villager"."werewolf"}

Output

For each test case,print the number of type-1 players and the number of type-2 players in one line, separated by white space.

Sample Input

1 2 2 werewolf 1 werewolf

Sample Output

0 0

 

题意:玩狼人杀,只有村民和狼人,村民一定讲真话,狼人可以讲假话。现在给定所有n个角色,以及每个角色所说的另外一个角色的身份,然后判断有多少角色一定是村民,有多少一定是狼人。

思路:一定是村民的角色为0,因为可以全是狼人,那么话就可以随便讲。那现在就是要找铁狼,建图连有向边,边分为2种,村民边和狼人边,表示箭尾说箭头角色的身份。通过寻找可能是村民的角色,排除之后剩下的就是铁狼。

瞎搞

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn = 1e5+10;
int n;
struct node
{
    int v;
    int type;
}edge[maxn];
int vis[maxn];
int cnt;
int sum;
int ind[maxn];
bool wf[maxn];
int dfs(int x)
{
    vis[x] = cnt;
    if(edge[x].type==0)
    {
        if(vis[edge[x].v]!=cnt)
        {
            return dfs(edge[x].v);
        }
        else
        {
            return 0;
        }
    }
    else
    {
        if(vis[edge[x].v]!=cnt)
        {
            return 0;
        }
        else return edge[x].v;
    }
}
void dfs2(int x,int e)
{
    if(!wf[x])
    {
        wf[x] = 1;
        sum++;
    }
    if(x==e)return;
    dfs2(edge[x].v,e);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(vis,0,sizeof(vis));
        memset(ind,0,sizeof(ind));
        memset(wf,0,sizeof(wf));
        scanf("%d",&n);
        char s[20];
        for(int i = 1;i<=n;i++)
        {
            scanf("%d %s",&edge[i].v,s);
            if(s[0]=='v')
            {
                edge[i].type = 0;
                ind[edge[i].v]++;
            }
            else edge[i].type = 1;
        }
        cnt = 0;
        int wolf = 0;
        for(int i = 1;i<=n;i++)
        {
            if(vis[i]==0&&!ind[i]&&edge[i].type==0)
            {
                ++cnt;
                int x = dfs(i);
                if(x)
                {
                    sum = 0;
                    dfs2(i,x);
                    wolf +=sum;
                }
            }
        }
        printf("0 %d\n",wolf);
    }
}

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值