//poj 1022
//sep9
#include <iostream>
using namespace std;
const int MAXN=128;
const int MAX_INDEX=1024;
int g[MAXN][MAXN][10];
int vis[MAXN],map[MAX_INDEX],minx[4],maxx[4],x[4];
int cases,n,cnt;
void dfs(int cur)
{
vis[cur]=1;
++cnt;
for(int i=1;i<=n;++i){
if(!vis[i]){
int flag=-1;
for(int j=0;j<8;++j)
if(g[cur][i][j]){
flag=j;
break;
}
if(flag>=0){
x[flag/2]+=((flag&1)==1?1:-1);
minx[flag/2]=min(minx[flag/2],x[flag/2]);
maxx[flag/2]=max(maxx[flag/2],x[flag/2]);
dfs(i);
x[flag/2]-=((flag&1)==1?1:-1);
}
}
}
}
bool judge1()
{
for(int i=1;i<=n;++i)
for(int j=1;j<=i;++j)
for(int k=0;k<8;++k)
if(g[i][j][k]!=g[j][i][k^1])
return false;
return true;
}
bool judge2()
{
cnt=0;
memset(vis,0,sizeof(vis));
memset(minx,0,sizeof(minx));
memset(maxx,0,sizeof(maxx));
memset(x,0,sizeof(x));
dfs(1);
return cnt==n;
}
int main()
{
scanf("%d",&cases);
while(cases--){
memset(g,0,sizeof(g));
memset(map,0,sizeof(map));
scanf("%d",&n);
int index=0;
for(int i=0;i<n;++i){
int x;
scanf("%d",&x);
if(!map[x]) map[x]=++index;
for(int j=0;j<8;++j){
int y;
scanf("%d",&y);
if(!y) continue;
if(!map[y]) map[y]=++index;
g[map[x]][map[y]][j]=1;
}
}
if(!judge1()||!judge2()){
puts("Inconsistent");
continue;
}
int ans=1;
for(int i=0;i<4;++i)
ans*=(maxx[i]-minx[i]+1);
printf("%d\n",ans);
}
return 0;
}
poj 1022 Packing Unit 4D Cubes 搜索
最新推荐文章于 2020-08-21 11:43:45 发布