import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashSet; import java.util.Set; public class kar { private static InputStream in; public static void main(String[] args) throws IOException { in = new BufferedInputStream(System.in); int t = nextInt(); for (int i = 0; i < t; i++) { solve(); } in.close(); } private static void solve() throws IOException { int n = nextInt(); int m = nextInt(); int a, b, w; Set<Integer> A = new HashSet<>(); Set<Integer> B = new HashSet<>(); for (int i = 0; i < m; i++) { a = nextInt(); w = nextInt(); b = nextInt(); if (w == -1) { A.add(a); } else { B.add(b); } } int p = A.size(); int q = B.size(); if (p == n && q < n) { System.out.println("WYGRANA"); return; } if (p < n && q == n) { System.out.println("PRZEGRANA"); return; } System.out.println("REMIS"); } private static int nextInt() throws IOException { int ret = 0; boolean dig = false; for (int c = 0; (c = in.read()) != -1; ) { if (c == '>') return -1; if (c == '<') return -2; if (c >= 48 && c <= 57) { dig = true; ret = ret * 10 + c - 48; } else if (dig) break; } return ret; } }
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 | import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashSet; import java.util.Set; public class kar { private static InputStream in; public static void main(String[] args) throws IOException { in = new BufferedInputStream(System.in); int t = nextInt(); for (int i = 0; i < t; i++) { solve(); } in.close(); } private static void solve() throws IOException { int n = nextInt(); int m = nextInt(); int a, b, w; Set<Integer> A = new HashSet<>(); Set<Integer> B = new HashSet<>(); for (int i = 0; i < m; i++) { a = nextInt(); w = nextInt(); b = nextInt(); if (w == -1) { A.add(a); } else { B.add(b); } } int p = A.size(); int q = B.size(); if (p == n && q < n) { System.out.println("WYGRANA"); return; } if (p < n && q == n) { System.out.println("PRZEGRANA"); return; } System.out.println("REMIS"); } private static int nextInt() throws IOException { int ret = 0; boolean dig = false; for (int c = 0; (c = in.read()) != -1; ) { if (c == '>') return -1; if (c == '<') return -2; if (c >= 48 && c <= 57) { dig = true; ret = ret * 10 + c - 48; } else if (dig) break; } return ret; } } |