#include <cstdio>
#include <queue>
#include <utility>
using namespace std;
#define P pair<int, int>
class Compare
{
public:
bool operator()(P const& one, P const& two)
{
return one.first < two.first;
}
};
priority_queue< P, vector< P >, Compare > q1, q2;
int tablica1[100010], tablica2[100010];
//tablica1 - dla Bajtka; status wierzcholkow Bitka
//tablica2 - dla Bitka
vector< pair< P, char> > v;
int main()
{
P one, two;
char w;
int n, m, i, a, b, t, j, wynik = 0;
scanf("%d", &t);
for (i = 0; i < t; i++)
{
wynik = 0;
scanf("%d %d", &n, &m);
for (j = 0; j < m; j++)
{
scanf("%d %c %d", &a, &w, &b);
if (w == '>')
{
tablica1[b]++;
tablica2[a]--;
}
else if (w == '<')
{
tablica1[b]--;
tablica2[a]++;
}
v.push_back(make_pair(make_pair(a, b), w));
}
for (j = 1; j <= n; j++)
{
q1.push(make_pair(tablica1[j], j));
q2.push(make_pair(tablica2[j], j));
}
one = q1.top();
two = q2.top();
//printf("one: %d %d\ntwo: %d %d\n", one.first, one.second, two.first, two.second);
for (vector< pair<P, char> >::iterator it = v.begin(); it != v.end(); it++)
{
if (two.second == (*it).first.first && one.second == (*it).first.second)
{
if ((*it).second == 62)
wynik = 1;
else
wynik = -1;
}
}
if (wynik == -1)
printf("PRZEGRANA\n");
else if (wynik == 0)
printf("REMIS\n");
else
printf("WYGRANA\n");
while (!q1.empty() || !q2.empty())
{
//printf("q1: %d %d | q2: %d %d\n", q1.top().first, q1.top().second, q2.top().first, q2.top().second);
q1.pop();
q2.pop();
}
v.erase(v.begin(), v.end());
for (j = 0; j < n; j++)
{
tablica1[j] = 0, tablica2[j] = 0;
}
}
return 0;
}
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 | #include <cstdio> #include <queue> #include <utility> using namespace std; #define P pair<int, int> class Compare { public: bool operator()(P const& one, P const& two) { return one.first < two.first; } }; priority_queue< P, vector< P >, Compare > q1, q2; int tablica1[100010], tablica2[100010]; //tablica1 - dla Bajtka; status wierzcholkow Bitka //tablica2 - dla Bitka vector< pair< P, char> > v; int main() { P one, two; char w; int n, m, i, a, b, t, j, wynik = 0; scanf("%d", &t); for (i = 0; i < t; i++) { wynik = 0; scanf("%d %d", &n, &m); for (j = 0; j < m; j++) { scanf("%d %c %d", &a, &w, &b); if (w == '>') { tablica1[b]++; tablica2[a]--; } else if (w == '<') { tablica1[b]--; tablica2[a]++; } v.push_back(make_pair(make_pair(a, b), w)); } for (j = 1; j <= n; j++) { q1.push(make_pair(tablica1[j], j)); q2.push(make_pair(tablica2[j], j)); } one = q1.top(); two = q2.top(); //printf("one: %d %d\ntwo: %d %d\n", one.first, one.second, two.first, two.second); for (vector< pair<P, char> >::iterator it = v.begin(); it != v.end(); it++) { if (two.second == (*it).first.first && one.second == (*it).first.second) { if ((*it).second == 62) wynik = 1; else wynik = -1; } } if (wynik == -1) printf("PRZEGRANA\n"); else if (wynik == 0) printf("REMIS\n"); else printf("WYGRANA\n"); while (!q1.empty() || !q2.empty()) { //printf("q1: %d %d | q2: %d %d\n", q1.top().first, q1.top().second, q2.top().first, q2.top().second); q1.pop(); q2.pop(); } v.erase(v.begin(), v.end()); for (j = 0; j < n; j++) { tablica1[j] = 0, tablica2[j] = 0; } } return 0; } |
English