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
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include <string.h>
#include <tuple>

#define MAX 100001
std::tuple<int, int, bool> tmp[200001];
int in[MAX], out[MAX];
bool hasAnyOuts[MAX];

void solve()
{
	int n, m, a, b;
	char c;
	scanf("%d %d", &n, &m);
	memset(in, 0, MAX);
	memset(out, 0, MAX);

	for (int i=0; i<m; ++i)
	{
		scanf("%d %c %d",&a, &c, &b);
		if (c == '>')
		{
			tmp[i]= std::make_tuple(a, b, true);
			in[b]++;
		}
		else
		{
			tmp[i]= std::make_tuple(a, b, false);
			out[b]++;
		}
	}

	memset(hasAnyOuts, false, MAX);
	int outsCount = 0;
	int insCount = 0;
	for (int i=1; i<=n; ++i)
		if (out[i])
		{
			outsCount++;
			hasAnyOuts[i] = true;
		}
		else if (in[i])
			insCount++;

	if (outsCount == n)
	{
		printf("PRZEGRANA\n");
		return ;
	}
	else if (insCount == 0)
	{
		printf("REMIS\n");
		return ;
	}

	memset(out, 0, MAX);
	memset(in, 0, MAX);
	for (int i=0; i<m; ++i)
		if (std::get<2>(tmp[i]) && !hasAnyOuts[std::get<1>(tmp[i])])
		{
			out[std::get<0>(tmp[i])]++;
			in[std::get<1>(tmp[i])]++;
		}

	int sum = 0;
	for (int i=1; i<=n; ++i)
	{
		sum += out[i];
		if (out[i] == 0)
		{
			printf("REMIS\n");
			return ;
		}
		if (in[i] == n)
		{
			printf("WYGRANA\n");
			return ;
		}
	}

	if (sum <= insCount * n)
		printf("REMIS\n");
	else
		printf("WYGRANA\n");
}

int main(int , char **)
{
	int t;
	scanf("%d", &t);
	for (int i=0; i<t; ++i)
		solve();
	return 0;
}