#include <stdio.h> #include <stdlib.h> #define MAXB 65536 #define MAXN 102400 int out[MAXN]; int in[MAXN]; int main() { char buf[MAXB]; int k, i, j, n, m; fgets(buf, MAXB, stdin); sscanf(buf, "%d", &k); for (j=0;j<k;j++) { fgets(buf, MAXB, stdin); sscanf(buf, "%d %d", &n, &m); for (i=0;i<=n;i++) { out[i] = in[i] = 0; } for (i=0;i<m;i++) { int w1, w2; char c, c1, c2; fgets(buf, MAXB, stdin); sscanf(buf, "%d %c %d", &w1, &c, &w2); if (c=='>') { // A -> B in[w2]++; } else { // B -> A out[w2]++; } } int xw1 = 0; int xw2 = 1; for (i=1;i<=n;i++) { if (out[i]==0) xw2 = 0; if (in[i]==n) xw1 = 1; } if (xw1==1) printf("WYGRANA\n"); else if (xw2==1) printf("PRZEGRANA\n"); else printf("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 | #include <stdio.h> #include <stdlib.h> #define MAXB 65536 #define MAXN 102400 int out[MAXN]; int in[MAXN]; int main() { char buf[MAXB]; int k, i, j, n, m; fgets(buf, MAXB, stdin); sscanf(buf, "%d", &k); for (j=0;j<k;j++) { fgets(buf, MAXB, stdin); sscanf(buf, "%d %d", &n, &m); for (i=0;i<=n;i++) { out[i] = in[i] = 0; } for (i=0;i<m;i++) { int w1, w2; char c, c1, c2; fgets(buf, MAXB, stdin); sscanf(buf, "%d %c %d", &w1, &c, &w2); if (c=='>') { // A -> B in[w2]++; } else { // B -> A out[w2]++; } } int xw1 = 0; int xw2 = 1; for (i=1;i<=n;i++) { if (out[i]==0) xw2 = 0; if (in[i]==n) xw1 = 1; } if (xw1==1) printf("WYGRANA\n"); else if (xw2==1) printf("PRZEGRANA\n"); else printf("REMIS\n"); } return 0; } |