Box Relations
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 301 Accepted Submission(s): 94
Special Judge
There are four kinds of relations (1 <= i,j <= n, i is different from j):
- I i j: The intersection volume of Ci and Cj is positive.
- X i j: The intersection volume is zero, and any point inside Ci has smaller x-coordinate than any point inside Cj.
- Y i j: The intersection volume is zero, and any point inside Ci has smaller y-coordinate than any point inside Cj.
- Z i j: The intersection volume is zero, and any point inside Ci has smaller z-coordinate than any point inside Cj.
Print a blank line after the output of each test case.
3 2 I 1 2 X 2 3 3 3 Z 1 2 Z 2 3 Z 3 1 1 0 0 0
Case 1: POSSIBLE 0 0 0 2 2 2 1 1 1 3 3 3 8 8 8 9 9 9 Case 2: IMPOSSIBLE Case 3: POSSIBLE 0 0 0 1 1 1
#include<stdio.h>
#include<string.h>
int n,r,e;
struct NODE
{
int v,next;
}p[900010];
int point[4][2010];
int q[4][2010],in[4][2010],ans[4][2010];
void addedge(int type,int u,int v)
{
p[e].v=v;
p[e].next=point[type][u];
point[type][u]=e++;
in[type][v]++;
}
void init()
{
e=0;
memset(in,0,sizeof(in));
memset(point,-1,sizeof(point));
for(int i=1;i<=n;i++)
for(int j=1;j<=3;j++)
addedge(j,i,i+n);
}
bool tuopu(int type)
{
int front=0,top=0;
for(int i=1;i<=2*n;i++)
if(in[type][i]==0) q[type][top++]=i,in[type][i]--;
while(front<top)
{
int u=q[type][front++];
for(int i=point[type][u];i!=-1;i=p[i].next)
{
int v=p[i].v;
in[type][v]--;
if(in[type][v]==0) q[type][top++]=v,in[type][v]--;
}
}
return top==2*n;
}
void solve()
{
for(int i=1;i<=3;i++)
{
if(!tuopu(i))
{
puts("IMPOSSIBLE");
return ;
}
}
puts("POSSIBLE");
for(int j=1;j<=3;j++)
for(int i=0;i<2*n;i++)
ans[j][q[j][i]]=i;
for(int i=1;i<=n;i++)
printf("%d %d %d %d %d %d/n",ans[1][i],ans[2][i],ans[3][i],ans[1][i+n],ans[2][i+n],ans[3][i+n]);
}
int main()
{
char str[10];
int x,y,cas=1;
while(scanf("%d%d",&n,&r)!=EOF)
{
if(n==0 && r==0) break;
init();
for(int i=1;i<=r;i++)
{
scanf("%s %d %d",str,&x,&y);
if(str[0]=='I')
{
for(int j=1;j<=3;j++)
{
addedge(j,x,y+n);
addedge(j,y,x+n);
}
}
else if(str[0]=='X') addedge(1,x+n,y);
else if(str[0]=='Y') addedge(2,x+n,y);
else if(str[0]=='Z') addedge(3,x+n,y);
}
printf("Case %d: ",cas++);
solve();
puts("");
}
return 0;
}