和食物链那题很像,只要把裁判枚举一遍即可,当前枚举的裁判不参与矛盾判断,没有矛盾的组数为0时,即Inpossible,大于1时就是Can not determine,等于1时是可以确定裁判的,裁判即没有出现矛盾的那一组枚举的人,判断轮数即所有枚举情况中的出现矛盾的最大轮数。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<bitset>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#define INF 0x3f3f3f3f
#define inf 2*0x3f3f3f3f
#define llinf 1000000000000000000
#define pi acos(-1.0)
#define mod 1000000007
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lrt rt<<1
#define rrt rt<<1|1
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define lb(x) (x&-x)
#define gi(x) scanf("%d",&x)
#define gi2(x,y) scanf("%d%d",&x,&y)
#define gll(x) scanf("%lld",&x)
#define gll2(x,y) scanf("%lld%lld",&x,&y)
#define gc(x) scanf("%c",&x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
/***********************************************/
int par[505*3],ranks[505*3],n,m,x,y;
struct node
{
int x,y;
char c;
}qu[2005];
void init(int n)
{
rep(i,0,n)par[i]=i,ranks[i]=0;
}
int finds(int x)
{
if(par[x]==x)return x;
return par[x]=finds(par[x]);
}
void unite(int x,int y)
{
x=finds(x);y=finds(y);
if(ranks[x]>ranks[y])par[y]=x;
else par[x]=y;
if(ranks[x]==ranks[y])ranks[y]++;
}
bool same(int x,int y)
{
return finds(x)==finds(y);
}
int main()
{
while(gi2(n,m)!=EOF)
{
rep(i,0,m)
{
gi(qu[i].x);
gc(qu[i].c);
gi(qu[i].y);
}
int flag=0,num=0,round=0;
rep(i,0,n)
{
int j=0;init(3*n);
for(;j<m;j++)
{
if(qu[j].x==i||qu[j].y==i)continue;
int x=qu[j].x,y=qu[j].y;
if(qu[j].c=='<')
{
if(same(x+n,y)||same(x,y)){round=max(round,j+1);break;}
else unite(x,y+n),unite(x+n,y+2*n),unite(x+2*n,y);
}
else if(qu[j].c=='>')
{
if(same(y+n,x)||same(x,y)){round=max(round,j+1);break;}
else unite(y,x+n),unite(y+n,x+2*n),unite(y+2*n,x);
}
else
{
if(same(x,y+n)||same(x+n,y)){round=max(round,j+1);break;}
else unite(x,y),unite(x+n,y+n),unite(x+2*n,y+2*n);
}
}
if(j==m)flag++,num=i;
}
if(flag==0)printf("Impossible\n");
else if(flag==1)printf("Player %d can be determined to be the judge after %d lines\n",num,round);
else printf("Can not determine\n");
}
return 0;
}