#include <bits/stdc++.h> using namespace std; typedef long long int64; #define DEBUG(x) cerr << #x << " = " << x << endl; #define REP(x, n) for(__typeof(n) x = 0; x < (n); ++x) #define FOR(x, b, e) for(__typeof(b) x = (b); x != (e); x += 1 - 2 * ((b) > (e))) const int INF = 1000000001; const double EPS = 10e-9; template<class V, class E> struct Graph { struct Edge : E { int v; Edge(E d, int w): E(d), v(w) { } }; struct Vertex : V, vector<Edge> { }; vector<Vertex> g; Graph(int n) : g(n) { } void edgeD(int b, int e, E d = E()) { g[b].push_back(Edge(d, e)); ++g[e].s; } void write() { REP(x, g.size()) { cout << x << ": "; for (auto it : g[x]) cout << it.v << " "; cout << "\n"; } } string solve() { int n = g.size() / 2; bool enemy = true; FOR(x, n, g.size()) { if (g[x].size() == 0) { enemy = false; break; } } if (enemy) { return "PRZEGRANA"; } FOR(x, n, g.size()) { if (g[x].s == n) { return "WYGRANA"; } } return "REMIS"; } }; struct Vs { int s = 0; }; struct Ve { }; #ifndef CATCH_TEST int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; REP(o, t) { int n, m; cin >> n >> m; Graph<Vs, Ve> g(2 * n); REP(x, m) { int b, e; char c; cin >> b >> c >> e; if (c == '>') { g.edgeD(b - 1, n + e - 1); } else { g.edgeD(n + e - 1, b - 1); } } cout << g.solve() << endl; } return 0; } #endif
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 | #include <bits/stdc++.h> using namespace std; typedef long long int64; #define DEBUG(x) cerr << #x << " = " << x << endl; #define REP(x, n) for(__typeof(n) x = 0; x < (n); ++x) #define FOR(x, b, e) for(__typeof(b) x = (b); x != (e); x += 1 - 2 * ((b) > (e))) const int INF = 1000000001; const double EPS = 10e-9; template<class V, class E> struct Graph { struct Edge : E { int v; Edge(E d, int w): E(d), v(w) { } }; struct Vertex : V, vector<Edge> { }; vector<Vertex> g; Graph(int n) : g(n) { } void edgeD(int b, int e, E d = E()) { g[b].push_back(Edge(d, e)); ++g[e].s; } void write() { REP(x, g.size()) { cout << x << ": "; for (auto it : g[x]) cout << it.v << " "; cout << "\n"; } } string solve() { int n = g.size() / 2; bool enemy = true; FOR(x, n, g.size()) { if (g[x].size() == 0) { enemy = false; break; } } if (enemy) { return "PRZEGRANA"; } FOR(x, n, g.size()) { if (g[x].s == n) { return "WYGRANA"; } } return "REMIS"; } }; struct Vs { int s = 0; }; struct Ve { }; #ifndef CATCH_TEST int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; REP(o, t) { int n, m; cin >> n >> m; Graph<Vs, Ve> g(2 * n); REP(x, m) { int b, e; char c; cin >> b >> c >> e; if (c == '>') { g.edgeD(b - 1, n + e - 1); } else { g.edgeD(n + e - 1, b - 1); } } cout << g.solve() << endl; } return 0; } #endif |