###### 【hdu】3231 Box Relations【拓扑排序三维】

#include<cstdio>
#include<cstring>
using namespace std;
const int N=1005;
const int M=100100;
bool inte[N][N];
struct node
{
int v,next;
}edge[M];
{
in[v]++;
edge[NE].v=v;
}
inline int x1(int a){return (a-1)*6;}
inline int y1(int a){return (a-1)*6+1;}
inline int z1(int a){return (a-1)*6+2;}
inline int x2(int a){return (a-1)*6+3;}
inline int y2(int a){return (a-1)*6+4;}
inline int z2(int a){return (a-1)*6+5;}
int topsort(int n,int id)
{
int level=0,cnt=0;
int i,now,k,t;
memset(vis,0,sizeof(vis));
while(1){
k=0;
for(i=0;i<n;i++){
now=i*6+id;
if(!vis[now]&&in[now]==0){
vis[now]=1;cnt++;
tmp[k++]=now;
A[now]=level;
}
now=i*6+3+id;
if(!vis[now]&&in[now]==0){
vis[now]=1;cnt++;
tmp[k++]=now;
A[now]=level;
}
}
if(cnt>=n*2)return 1;
if(!k) return 0;
for(i=0;i<k;i++){
t=tmp[i];
}
level++;
}
}
int main()
int kase=0,n,m,i,a,b;
char s[10];
while(scanf("%d%d",&n,&m)&&n+m){
while(m--){
scanf("%s%d%d",s,&a,&b);
if(s[0]=='I'&&!inte[a][b]){
inte[a][b]=inte[b][a]=1;
}
}
if(topsort(n,0)&&topsort(n,1)&&topsort(n,2)){//对三维各自进行拓扑排序
printf("Case %d: POSSIBLE\n",++kase);
for(i=0;i<n;i++)printf("%d %d %d %d %d %d\n",A[i*6],A[i*6+1],A[i*6+2],A[i*6+3],A[i*6+4],A[i*6+5]);
}
else {printf("Case %d: IMPOSSIBLE\n",++kase);}
printf("\n");
}
return 0;
}

#### Hdu 3231 Box Relations（拓扑排序）

2016-08-16 22:01:47

#### HDU3231Box Relations

2016-04-10 17:21:04

#### Hdu3231【拓扑排序】

2016-02-13 17:54:26

#### HDU 3231 Box Relations（拓扑排序）

2012-10-04 08:30:59

#### HDU3231 Box Relations（拓扑排序）经典

2015-05-01 00:13:00

#### 【拓扑排序】【HDU3231】【Box Relations】

2015-05-06 01:49:45

#### HDU 3231Box Relations 拓扑排序

2011-10-20 11:16:15

#### hdu 3231 Box Relations(拓扑排序)

2015-09-29 00:46:46

#### hdu 3231 Box Relations

2013-07-15 11:49:15

#### HDU 3231 Box Relations

2011-06-30 10:17:00

## 不良信息举报

【hdu】3231 Box Relations【拓扑排序三维】