HDU 6370 Werewolf 【基环内向树】(2018多校6)

11 篇文章 0 订阅
4 篇文章 0 订阅

Werewolf

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

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


题意:狼人杀... 有 村民,狼人,村民只能说真话,狼人能说真话也能说假话

输入玩家数量,然后一次输入玩家的指认 , 玩家的指认语句是   x编号 werewolf (villager)  ,表示指认 x 编号的玩家是村民或者狼人

现在要你确认有多少人一定是村民,有多少人一定是狼人

1.由于狼人既可以说真话也可以说假话,所以全部是狼人的情况是合法的,所以一定无法确认村民的身份,只能确认狼人的身份

2. 确认狼人的方法:就是让玩家为村民的假设不成立,既然不能是村民,那么必然是狼人

例如:1 指认 2 是村民,2 指认3是村民,3指认1是狼人,那么假设1是村民,那么2也是村民,那么3也是村民,村民都只能说真话,3指认1是狼人,与1是村民的假设相矛盾,所以1是村民的假设不成立,所以1一定是狼人,确定了1是狼人之后,所有指认1是村民的玩家也一定是狼人(因为村民必须说真话),以此类推

3.所以要找出所有的环,并且这个环里面只有一个人指认他人为狼人,那么被指认为狼人的人一定是狼人,然后再把指认狼人为村民的玩家全部标为狼人,以此类推

#pragma comment(linker, "/STACK:102400000,102400000")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define mem(a,x) memset(a,x,sizeof(a))
const int maxn = 1e5 + 5;
int du[maxn],nxt[maxn],p[maxn];
vector<int> pre[maxn];
int main() {
	int T,n,x;
	char str[10];
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		for(int i = 1; i <= n; i++) {
			du[i] = 0;
			pre[i].clear();
		}
		for(int i = 1; i <= n; i++) {
			scanf("%d %s",&x,str);
			du[x]++;
			nxt[i] = x;
			pre[x].push_back(i);
			if(str[0] == 'v') {
				p[i] = 0;  // person
			} else {
				p[i] = 1;  // wolf
			}
		}
		for(int i = 1; i <= n; i++) {
			int tmp = i;
			while(du[tmp] == 0 && du[nxt[tmp]] > 0) {
				du[tmp]--;
				du[nxt[tmp]]--;
				tmp = nxt[tmp];
			}
		}
		int ans1 = 0;
		for(int i = 1; i <= n; i++) {
			int tmp = i;
			int wolf = 0;
			int idx = -1;
			while(du[tmp] == 1) {
				du[tmp]--;
				if(p[tmp] == 1) {
					idx = nxt[tmp];
					wolf++;
				}
				tmp = nxt[tmp];
			}
			if(wolf == 1) {
				ans1++;
				queue<int>que;
				int sz = pre[idx].size();
				for(int j = 0; j < sz; j++) {
					if(p[pre[idx][j]] == 0)
						que.push(pre[idx][j]);
				}
				while(!que.empty()) {
					int now = que.front();
					que.pop();
					if(p[now] == 0) {
						ans1++;
						int szs = pre[now].size();
						for(int j = 0; j < szs; j++) {
							if(p[pre[now][j]] == 0)
								que.push(pre[now][j]);
						}
					}
				}
			}
		}
		printf("0 %d\n",ans1);
	}
	return 0;
}
/*
1
8
3 w
1 v
2 v
3 v
4 w
3 v
6 w
6 v
*/

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值