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
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <cstring>


struct Pack
{
    unsigned char wins = 0;
    unsigned char loses = 0;

    inline void incWins()
    {
        if (wins < 2)
            ++wins;
    }

    inline void incLoses()
    {
        if (loses < 2)
            ++loses;
    }
};


bool HasWinningStrategy(Pack *player, Pack *opponent, unsigned int packs, bool second)
{
    for (unsigned int i = 0; i < packs; ++i) {
        if (player[i].wins == 0)
            return false;
    }

    if (!second) {
        for (unsigned int i = 0; i < packs; ++i) {
            if (opponent[i].loses > 1 || opponent[i].loses == 0)
                return true;
        }
        return false;
    }
    return true;
}


int main()
{
    unsigned int cases;
    std::cin >> cases;

    for (unsigned int case_i = 0; case_i < cases; ++case_i) {
        unsigned int packs, edges;
        std::cin >> packs >> edges;
        Pack *bajtek = new Pack [packs];
        Pack *bitek = new Pack [packs];

        for (unsigned int i = 0; i < edges; ++i) {
            unsigned int ba, bi;
            char dir;
            std::cin >> ba >> std::ws >> dir >> std::ws >> bi;
            if (dir == '>') {
                bajtek[ba - 1].incWins();
                bitek[bi - 1].incLoses();
            } else if (dir == '<') {
                bajtek[ba - 1].incLoses();
                bitek[bi - 1].incWins();
            } else {
                std::cerr << "FAIL: invalid character (" << dir << ") read in edge " << i << " of test " << case_i << std::endl;
                return 1;
            }
        }

        if (HasWinningStrategy(bitek, bajtek, packs, true))
            std::cout << "PRZEGRANA" << std::endl;
        else if (HasWinningStrategy(bajtek, bitek, packs, false))
            std::cout << "WYGRANA" << std::endl;
        else
            std::cout << "REMIS" << std::endl;

        delete [] bajtek;
        delete [] bitek;
    }

    return 0;
}