#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define st first #define nd second typedef pair<int,int> pii; vector<int> k1, k2; vector<vector<int> > v1, v2; set<pii> S1, S2; set<pii>::iterator it; int main() { ios::sync_with_stdio(0); int t; cin>>t; while(t--) { k1.clear(); k2.clear(); v1.clear(); v2.clear(); S1.clear(); S2.clear(); int n, m; cin>>n>>m; k1.resize(n,0); k2.resize(n,0); v1.resize(n); v2.resize(n); while(m--) { int a, b; char w; cin>>a>>w>>b; --a; --b; if(w=='>') { v2[b].pb(a); ++k1[a]; } else { v1[a].pb(b); ++k2[b]; } } for(int i=0; i<n; ++i) { S1.insert(mp(-k1[i],i)); S2.insert(mp(-k2[i],i)); } for(int i=0; i<n-1; ++i) { it = S2.begin(); pii p = *it; S2.erase(it); S2.insert(mp(0,p.nd)); k2[p.nd] = 0; for(int j=0; j<v2[p.nd].size(); ++j) { int u = v2[p.nd][j]; it = S1.find(mp(-k1[u],u)); S1.erase(it); --k1[u]; S1.insert(mp(-k1[u],u)); } it = S1.begin(); p = *it; S1.erase(it); S1.insert(mp(0,p.nd)); k1[p.nd] = 0; for(int j=0; j<v1[p.nd].size(); ++j) { int u = v1[p.nd][j]; it = S2.find(mp(-k2[u],u)); S2.erase(it); --k2[u]; S2.insert(mp(-k2[u],u)); } } if(S1.begin()->st != 0) { cout<<"WYGRANA\n"; } else if(S2.begin()->st != 0) { cout<<"PRZEGRANA\n"; } else cout<<"REMIS\n"; } 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 88 89 90 91 92 93 94 95 | #include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define st first #define nd second typedef pair<int,int> pii; vector<int> k1, k2; vector<vector<int> > v1, v2; set<pii> S1, S2; set<pii>::iterator it; int main() { ios::sync_with_stdio(0); int t; cin>>t; while(t--) { k1.clear(); k2.clear(); v1.clear(); v2.clear(); S1.clear(); S2.clear(); int n, m; cin>>n>>m; k1.resize(n,0); k2.resize(n,0); v1.resize(n); v2.resize(n); while(m--) { int a, b; char w; cin>>a>>w>>b; --a; --b; if(w=='>') { v2[b].pb(a); ++k1[a]; } else { v1[a].pb(b); ++k2[b]; } } for(int i=0; i<n; ++i) { S1.insert(mp(-k1[i],i)); S2.insert(mp(-k2[i],i)); } for(int i=0; i<n-1; ++i) { it = S2.begin(); pii p = *it; S2.erase(it); S2.insert(mp(0,p.nd)); k2[p.nd] = 0; for(int j=0; j<v2[p.nd].size(); ++j) { int u = v2[p.nd][j]; it = S1.find(mp(-k1[u],u)); S1.erase(it); --k1[u]; S1.insert(mp(-k1[u],u)); } it = S1.begin(); p = *it; S1.erase(it); S1.insert(mp(0,p.nd)); k1[p.nd] = 0; for(int j=0; j<v1[p.nd].size(); ++j) { int u = v1[p.nd][j]; it = S2.find(mp(-k2[u],u)); S2.erase(it); --k2[u]; S2.insert(mp(-k2[u],u)); } } if(S1.begin()->st != 0) { cout<<"WYGRANA\n"; } else if(S2.begin()->st != 0) { cout<<"PRZEGRANA\n"; } else cout<<"REMIS\n"; } return 0; } |