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
| #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<climits> #include<string> #include<vector> #include<stack> #include<queue> #include<deque> #include<set> #include<map> #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(),(x).end() #define PB push_back #define MP make_pair #define FI first #define SE second using namespace std; typedef double DB; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<PII> VPII;
const int N=505; int fa[N],w[N],st[N]; struct R { int x,y,z; R() {} R(int x,int y,int z):x(x),y(y),z(z) {} }r[N<<2]; int find(int x) { if(x==fa[x]) return x; int root=find(fa[x]); w[x]=(w[x]+w[fa[x]])%3; return fa[x]=root; } int main() { int n,m; while(~scanf("%d%d",&n,&m)) { for(int i=1;i<=m;i++) { int x,y; char c; scanf("%d%c%d",&x,&c,&y); if(c=='=') r[i]=R(x,y,0); else if(c=='<') r[i]=R(x,y,2); else if(c=='>') r[i]=R(x,y,1); } int cnt=0; PII res=MP(0,0); for(int i=0;i<n;i++) { int f=0; for(int j=0;j<n;j++) fa[j]=j,w[j]=0; for(int j=1;j<=m;j++) { if(r[j].x==i||r[j].y==i) continue; int tx=find(r[j].x),ty=find(r[j].y); if(tx==ty) { if((w[r[j].x]-w[r[j].y]+3)%3!=r[j].z) { f=j; break; } } else { fa[tx]=ty; w[tx]=(w[r[j].y]+r[j].z-w[r[j].x]+3)%3; } } if(!f) res.FI=i,cnt++; else res.SE=max(res.SE,f); } if(cnt==1) { printf("Player %d can be determined to be the judge after %d lines\n",res.FI,res.SE); } else if(cnt==0) { puts("Impossible"); } else { puts("Can not determine"); } } return 0; }
|