#include<iostream>
using namespace std;
typedef class {
public :
int next[27];
int po;
}point;//数字标记节点和颜色种类,一个节点的数据类型包括相邻节点名称和相邻总结点数
int main()
{
int n;
while(cin>>n&&n)
{
getchar ();
point *node=new point[n+1];
for(int i=1;i<=n;++i)
{
getchar();//循环顺序对应节点顺序无须输入
getchar();//字符型逐个输入时注意抵消无用符号
char ch;
node[i].po=0;//初始化
while((ch=getchar())!='\n')
{
node[i].next[++node[i].po]=(ch%('A'-1));//节点数字化
}
}
int color[27]={0};//节点与颜色的对应
color[1]=1;
int max=1;//最多色种(方便四色剪枝)
for(int i=1;i<=n;++i)
{
color[i]=n+1;
bool vis[27]={false};//标记每个节点相邻处已经出现的颜色
for(int j=1;j<=node[i].po;++j)
{
if(color[node[i].next[j]])
{
vis[color[node[i].next[j]]]=true;
}
}
for(int j=1;j<=n;++j)
{
if(!vis[j]&&j<color[i])
{
color[i]=j;
break;//使当前为不受限内最小颜色
}
}
if(max<color[i])
{
max=color[i];
if(max>=4)
break;//四色剪枝
}
}
if(max==1)//输出形式
cout<<1<<" channel needed."<<endl;
else cout<<max<<" channels needed."<<endl;
delete node;
}
return 0;
}
05-28
6725
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交