1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <cstdio>
#include <cstdint>
#include <vector>

struct vertex {
    std::vector<int> edges;
};

int main() {

    int t;
    scanf("%d\n", &t);
    
    for (int i = 0; i < t; ++i)
    {
        uint32_t n, m;
        std::vector<vertex> player_a;
        std::vector<vertex> player_b;

        scanf("%d %d\n", &n, &m);
        player_a.resize(n);
        player_b.resize(n);

        for (size_t i = 0; i < m; ++i) {
            int a, b;
            char c;
            scanf("%d %c %d", &a, &c, &b);
            if (c=='>') {
                player_a[a-1].edges.push_back(b);
            } else {
                player_b[b-1].edges.push_back(a);
            }
        }

        bool player_b_wins = true;
        for (auto &&deck : player_b)
            player_b_wins &= !deck.edges.empty();

        if (player_b_wins) 
        {
            printf("PRZEGRANA\n");
            continue;
        }

        std::vector<int> counts;
        counts.resize(n+1);
        for (auto &&deck : player_a)
            for (auto &&v : deck.edges)
                ++counts[v];

        bool player_a_wins = false;
        for (auto &&rank : counts)
            if (rank == n)
            {
                player_a_wins = true;
                break;
            }

        if (player_a_wins)
        {
            printf("WYGRANA\n");
            continue;
        }

        printf("REMIS\n");
    }

    return 0;
}