# include <stdio.h>
# include <string.h>
int d[100009]; //表示每一个边的连接数
int n,m;
bool isbus()
{
int i;
for(i=1;i<=n;i++)
{
if(d[i]>2) return false;
}
return true;
}
bool isstar()
{
int i,cnt=0; //cnt表示的是连接数大于1的点的个数
for(i=1;i<=n;i++)
{
if(d[i]>1) cnt++;
}
return (cnt==1);
}
bool isring()
{
int i;
for(i=1;i<=n;i++)
if(d[i]!=2) return false;
return true;
}
int main ()
{
int x,y,i;
memset(d,0,sizeof(d));
scanf("%d %d",&n,&m);
for(i=0;i<m;i++)
{
scanf("%d %d",&x,&y);
d[x]++;d[y]++;
}
if(n-1==m)
{
if(isbus()) printf("bus topology\n");
else if(isstar()) printf("star topology\n");
else printf("unknown topology\n");
}
else if(m==n&&isring())
printf("ring topology\n");
else
printf("unknown topology\n");
return 0;
}
这题的要求就是判断是一个什么图 有连试图 还有星图 还有环状图 这对于点和边的判断是有要求的 环状图是点和边的数量相等 还有就是每一个边的连接数都是2 对于连试图就是不超过2 对于在星状图 就是连接数大于1 的点只有一个
Croc Champ 2013 - Round 1 B. Network Topology
最新推荐文章于 2020-07-30 15:05:16 发布