#include <cstdio> #include <cstdlib> #include <iterator> #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <vector> #include <cmath> #include <cstring> #include <stack> #include <queue> #include <map> #include <set> using namespace std; typedef pair<int, int> PII; typedef pair<double, double> PDD; typedef vector<PII > VPII; typedef vector<PDD > VPDD; typedef vector<int> VI; typedef vector<long long> VLL; typedef vector<double> VD; typedef vector<string> VS; typedef long long LL; typedef long double LD; #define CLR(x,a) memset(x,a,sizeof(x)) #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define VAR(v, n) __typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define FOREACH(i, c) for(VAR(i, (c).begin()); i!= (c).end(); ++i) #define MIN(a, b) ((a) < (b)) ? (a) : (b) #define MAX(a, b) ((a) > (b)) ? (a) : (b) #define ABS(a) ((a) > 0 ? (a) : (-(a))) #define PB push_back #define PF push_front #define MP make_pair #define ST first #define ND second #define INF 1000000009 //duża liczba #define EPS (10e-9) //mała liczba #define PI 3.14159265358979323846 #define RET return LL gcd(LL n, LL m){return m==0?n:gcd(m,n%m);} int gcd(int n, int m){return m==0?n:gcd(m,n%m);} inline bool IsZero(LD x){return (x>-EPS && x<EPS);} struct node{ int number; set<int> sout; vector<int> sin; }; bool cmp(const node* a, const node* b){ if(a->sout.size()==b->sout.size()){ if(a->sin.size()==b->sin.size()){ return a->number<b->number; }else{ return a->sin.size()<b->sin.size(); } } return a->sout.size()>b->sout.size(); } void wypisz(set<node*, bool(*)(const node*, const node*) > s){ cout<<"set:"<<endl; FOREACH(it, s){ cout<<(*it)->number<<";"<<((*it)->sin).size()<<";"<<((*it)->sout).size()<<endl; } } set<node*, bool(*)(const node*, const node*) > v1(cmp), v2(cmp); vector<node> vv1, vv2; int t, n, m, a, b; char c; int main(){ scanf("%d", &t); while(t--){ v1.clear(); v2.clear(); vv1.clear(); vv2.clear(); scanf("%d %d", &n, &m); REP(i, n+1){ node tmp, tmp1; tmp.number=i; tmp1.number=i; vv1.PB(tmp); vv2.PB(tmp1); } REP(i, m){ scanf("%d %c %d", &a, &c, &b); if(c=='>'){ vv1[a].sout.insert(b); vv2[b].sin.PB(a); }else{ vv2[b].sout.insert(a); vv1[a].sin.PB(b); } } FOR(i, 1, n){ v1.insert(&vv1[i]); v2.insert(&vv2[i]); } FOR(i, 2, n){ node q = *(*(v2.begin())); //cout<<"zzz"<<endl; REP(j, q.sin.size()){ int w = q.sin[j]; vv1[w].sout.erase(q.number); v1.erase((node*)&vv1[w]); v1.insert((node*)&vv1[w]); } v2.erase(v2.begin()); //cout<<"xxx"<<endl; node q1 = *(*(v1.begin())); REP(j, q1.sin.size()){ int w = q1.sin[j]; vv2[w].sout.erase(q1.number); v2.erase((node*)&vv2[w]); v2.insert((node*)&vv2[w]); } v1.erase(v1.begin()); //cout<<"yyy"<<endl; //wypisz(v1); //wypisz(v2); } int a1=(*v1.begin())->sout.size(); int a2=(*v2.begin())->sout.size(); if(a1==a2){ printf("REMIS\n"); }else if (a1>a2){ printf("WYGRANA\n"); }else{ printf("PRZEGRANA\n"); } } RET 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | #include <cstdio> #include <cstdlib> #include <iterator> #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <vector> #include <cmath> #include <cstring> #include <stack> #include <queue> #include <map> #include <set> using namespace std; typedef pair<int, int> PII; typedef pair<double, double> PDD; typedef vector<PII > VPII; typedef vector<PDD > VPDD; typedef vector<int> VI; typedef vector<long long> VLL; typedef vector<double> VD; typedef vector<string> VS; typedef long long LL; typedef long double LD; #define CLR(x,a) memset(x,a,sizeof(x)) #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define VAR(v, n) __typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define FOREACH(i, c) for(VAR(i, (c).begin()); i!= (c).end(); ++i) #define MIN(a, b) ((a) < (b)) ? (a) : (b) #define MAX(a, b) ((a) > (b)) ? (a) : (b) #define ABS(a) ((a) > 0 ? (a) : (-(a))) #define PB push_back #define PF push_front #define MP make_pair #define ST first #define ND second #define INF 1000000009 //duża liczba #define EPS (10e-9) //mała liczba #define PI 3.14159265358979323846 #define RET return LL gcd(LL n, LL m){return m==0?n:gcd(m,n%m);} int gcd(int n, int m){return m==0?n:gcd(m,n%m);} inline bool IsZero(LD x){return (x>-EPS && x<EPS);} struct node{ int number; set<int> sout; vector<int> sin; }; bool cmp(const node* a, const node* b){ if(a->sout.size()==b->sout.size()){ if(a->sin.size()==b->sin.size()){ return a->number<b->number; }else{ return a->sin.size()<b->sin.size(); } } return a->sout.size()>b->sout.size(); } void wypisz(set<node*, bool(*)(const node*, const node*) > s){ cout<<"set:"<<endl; FOREACH(it, s){ cout<<(*it)->number<<";"<<((*it)->sin).size()<<";"<<((*it)->sout).size()<<endl; } } set<node*, bool(*)(const node*, const node*) > v1(cmp), v2(cmp); vector<node> vv1, vv2; int t, n, m, a, b; char c; int main(){ scanf("%d", &t); while(t--){ v1.clear(); v2.clear(); vv1.clear(); vv2.clear(); scanf("%d %d", &n, &m); REP(i, n+1){ node tmp, tmp1; tmp.number=i; tmp1.number=i; vv1.PB(tmp); vv2.PB(tmp1); } REP(i, m){ scanf("%d %c %d", &a, &c, &b); if(c=='>'){ vv1[a].sout.insert(b); vv2[b].sin.PB(a); }else{ vv2[b].sout.insert(a); vv1[a].sin.PB(b); } } FOR(i, 1, n){ v1.insert(&vv1[i]); v2.insert(&vv2[i]); } FOR(i, 2, n){ node q = *(*(v2.begin())); //cout<<"zzz"<<endl; REP(j, q.sin.size()){ int w = q.sin[j]; vv1[w].sout.erase(q.number); v1.erase((node*)&vv1[w]); v1.insert((node*)&vv1[w]); } v2.erase(v2.begin()); //cout<<"xxx"<<endl; node q1 = *(*(v1.begin())); REP(j, q1.sin.size()){ int w = q1.sin[j]; vv2[w].sout.erase(q1.number); v2.erase((node*)&vv2[w]); v2.insert((node*)&vv2[w]); } v1.erase(v1.begin()); //cout<<"yyy"<<endl; //wypisz(v1); //wypisz(v2); } int a1=(*v1.begin())->sout.size(); int a2=(*v2.begin())->sout.size(); if(a1==a2){ printf("REMIS\n"); }else if (a1>a2){ printf("WYGRANA\n"); }else{ printf("PRZEGRANA\n"); } } RET 0; } |