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
| #include <iostream> #include "algorithm" #include "cstdio" #include "queue" #include "set" #include "cstring" #include "string" #define esp 1e-6 using namespace std; typedef long long ll; typedef unsigned long long ull; const int INF = 0x3f3f3f3f; const int N = 1e5 + 5; int f[N];
struct node{ int a, b, f; }no[N];
int tofind(int x){ if (f[x] != x) f[x] = tofind(f[x]); return f[x]; }
void tojoin(int x, int y){ x = tofind(x); y = tofind(y); if (x != y) f[x] = y; } set<int> se; int main(){ int n, m; int a, b, k; char c; while(cin >> n >> m){ for (int i = 0; i <= 3 * n; i++){ f[i] = i; } se.clear(); for (int i = 1; i <= m; i++){ cin >> a >> c >> b; no[i].a = a, no[i].b = b; if (c == '=') no[i].f = 0; else if (c == '>') no[i].f = 1; else if (c == '<') no[i].f = -1; } int ff = 1, j, pos = 0; for (int i = 0; i < n; i++){ for (j = 0; j <= 3 * n; j++){ f[j] = j; } for (j = 1; j <= m; j++){ a = no[j].a, b = no[j].b, k = no[j].f; if (a != i && b != i){ if (k == 0){ if (tofind(a) == tofind(b + n) || tofind(b) == tofind(a + n)){ ff = 0; break; } tojoin(a, b); tojoin(a + n, b + n); tojoin(a + 2 * n, b + 2 * n); } else if (k == 1){ if (tofind(a) == tofind(b) || tofind(a + n) == tofind(b)){ ff = 0; break; } tojoin(a, b + n); tojoin(a + n, b + 2 * n); tojoin(a + 2 * n, b); } else if (k == -1){ if (tofind(a) == tofind(b) || tofind(a) == tofind(b + n)){ ff = 0;
break; } tojoin(b, a + n); tojoin(b + n, a + 2 * n); tojoin(b + 2 * n, a); } } } if (ff) se.insert(i); else pos = max(pos, j); ff = 1; } k = se.size();
if (k == 0) puts("Impossible"); else if (k > 1) puts("Can not determine"); else if (k == 1){ printf("Player %d can be determined to be the judge after %d lines\n", *se.begin(), pos); }
} return 0; }
|