The integration and maintenance of collections are the same as those of the food chain.
However, there is an additional referee. Note that N <= 500, so you can enumerate the referee and determine whether there is a conflict. (Ignore the referee)
If there is a conflict, this person is not a referee.
The only difficulty is to output the rows of judgments.
I thought it was the last line of the referee.
Later, we found that the maximum value of the conflict should appear for the first time when we enumerated other people. (Think about it)
This solves the problem.
[Code]
[Cpp]
# Include <iostream>
# Include <cstring>
# Include <string>
# Include <cstdio>
# Include <algorithm>
Using namespace std;
Const int N = 505, M = 2005;
Int fa [N], r [N], x [M], y [M], z [M];
Int n, m, k, kk, ans;
Int find (int x)
{
If (fa [x] = x) return x;
Int t = fa [x];
Fa [x] = find (fa [x]);
R [x] = (r [x] + r [t]) % 3;
Return fa [x];
}
Int main ()
{
Int I, j, fx, fy;
Bool ff;
Char c;
Freopen ("in", "r", stdin );
While (scanf ("% d", & n, & m )! = EOF)
{
For (I = 1; I <= m; I ++)
{
Scanf ("% d % c % d", & x [I], & c, & y [I]);
If (c = '<') z [I] = 2;
Else if (c = '>') z [I] = 1;
Else z [I] = 0;
}
Ans = k = kk = 0;
For (j = 0; j <n; j ++)
{
Ff = true;
For (I = 0; I <n; I ++)
{
Fa [I] = I;
R [I] = 0;
}
For (I = 1; I <= m; I ++)
{
If (x [I] = j | y [I] = j) continue;
Fx = find (x [I]); fy = find (y [I]);
If (fx! = Fy)
{
Fa [fy] = fx;
R [fy] = (r [x [I]-r [y [I]-z [I] + 6) % 3;
}
Else if (r [x [I]-r [y [I] + 3) % 3! = Z [I])
{
Ff = false;
Kk = max (kk, I );
Break;
}
}
If (ff)
{
Ans ++; k = j;
If (ans> 1) break;
}
}
If (ans = 0) printf ("Impossible \ n ");
Else if (ans> 1) printf ("Can not determine \ n ");
Else printf ("Player % d can be determined to be the judge after % d lines \ n", k, kk );
}
}
Author: ascii991