#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int n, m, fa[1505], pla1[2005], pla2[2005], winn[2005], det[505], cntn, maxn,whic;
char opt;
int myfind(int x){
return fa[x]==x?x:fa[x]=myfind(fa[x]);
}
int chk(int x){
for(int i=0; i<3*n; i++) fa[i] = i;
for(int i=1; i<=m; i++){
if(pla1[i]==x || pla2[i]==x) continue;
int uu1=myfind(pla1[i]), uu2=myfind(pla1[i]+n), uu3=myfind(pla1[i]+n+n);
int vv1=myfind(pla2[i]), vv2=myfind(pla2[i]+n), vv3=myfind(pla2[i]+n+n);
if(winn[i]==1){
if(uu1==vv1 || uu2==vv1) return i;
fa[vv2] = uu1;
fa[vv3] = uu2;
fa[vv1] = uu3;
}
else if(!winn[i]){
if(uu1==vv2 || uu2==vv1) return i;
fa[vv1] = uu1;
fa[vv2] = uu2;
fa[vv3] = uu3;
}
else{
if(uu1==vv1 || uu1==vv2) return i;
fa[vv1] = uu2;
fa[vv2] = uu3;
fa[vv3] = uu1;
}
}
return 0;
}
int main(){
while(scanf("%d %d", &n, &m)!=EOF){
for(int i=1; i<=m; i++){
scanf("%d%c%d", &pla1[i], &opt, &pla2[i]);
if(opt==‘=‘) winn[i] = 0;
else winn[i] = opt==‘>‘?1:-1;
}
for(int i=0; i<n; i++) det[i] = chk(i);
cntn = maxn = 0;
for(int i=0; i<n; i++){
if(!det[i]) cntn++, whic=i;
maxn = max(maxn, det[i]);
}
if(!cntn) printf("Impossible\n");
else if(cntn>1) printf("Can not determine\n");
else printf("Player %d can be determined to be the judge after %d lines\n", whic, maxn);
}
return 0;
}
POJ 2912 Rochambeau
Posted poorpool
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ 2912 Rochambeau相关的知识,希望对你有一定的参考价值。
以上是关于POJ 2912 Rochambeau的主要内容,如果未能解决你的问题,请参考以下文章