Werewolf 2018杭电多校第六场I

Werewolf

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


 

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

题意 每个人都可以说某个人除了自己外是村民或狼 求出肯定是村民和肯定是狼的数量

题解 肯定是村民的肯定不存在 因为全部都是狼的情况满足所有,然后求狼的数量 发现当 1说2是狼并且 2说1是村民时 2肯定是狼  或者1说2是狼 2说3是村民 3说1是村民时 2肯定是狼 这样传递的也行 就确定了一些狼 然后在遍历找说这些狼是村民的人

做法是循环找第一部分的狼 并查集找父亲节点

确定他说的是假话

#include<bits/stdc++.h>

using namespace std;
const double PI=acos(-1.0);
typedef long long ll;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define clr(x) memset(x,0,sizeof(x))
const int INF = 0x3f3f3f3f;
const int MAXN = 100005;
int w[MAXN];
int v[MAXN];
int par[MAXN];
int Rank[MAXN];
bool a[MAXN];

void init(int n) {
    for (int i = 1; i <= n; ++i) {
        par[i] = i;
        Rank[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x || a[x]) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    //本地测试
    #ifdef ONLINE_JUDGE
    #else
    freopen("C://Users//yan//Desktop//in.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);//取消同步
    std::cin.tie(0);//解除cin与cout的绑定,进一步加快执行效率。
    int t;
    cin >> t;
    while (t--) {
        clr(a);
        clr(w);
        clr(v);
        char s[15];
        int n;
        cin >> n;
        init(n);
        rep(i,1,n+1){
            int pos;
            cin >> pos >> s;
            if (s[0] == 'w') {
                w[i] = pos;
            } else {
                v[i] = pos;
            }
        }
        rep(i,1,n+1){
            if (w[i] != 0) {
                int temp = w[i];
                set<int> si;
                int size = 0;
                si.insert(w[i]);
                while (v[temp] != 0 && size != si.size()) {
                    size = int(si.size());
                    temp = v[temp];
                    si.insert(temp);
                }
                if (temp == i) {
                    a[w[i]] = true;
                }
            }
        }
        rep(i,1,n+1){
            if (v[i])  {
                par[i] = find(v[i]);
            }
        }
        int sum = 0;
        rep(i,1,n+1){
            sum += a[find(i)];
        }
        cout << "0 " << sum << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/remarkableyan/article/details/81514254
今日推荐