图着色问题
程序员文章站
2022-06-09 18:02:09
...
#include <cstdio>
#include <string>
using namespace std;
int MAP[10][10];
int n,m;
int Bool[10];
int main()
{
int Queue[1000],tail=0,head=0;
int t1,t2;
scanf("%d %d",&n,&m);
for(int i=0;i<m;i++)
{
scanf("%d %d",&t1,&t2);
MAP[t1][t2] = 1;
MAP[t2][t1] = 1;
}
Queue[tail++]=1;
Bool[1] = 1;
while(tail!=head)
{
for(int i=0;i<10;i++)
{
if(MAP[Queue[head]][i] == 1 && Bool[i] != 1){
// printf("%d ",i);
Queue[tail++] = i;
Bool[i] = 1;
}
}
head++;
}
for(int i=0;i<tail;i++)
printf("%d ",Queue[i]);
return 0;
}