qi zi

#include<stdio.h>
int vist[100];
int map[100][100];
int N;
typedef struct node{
    int x;
}node;
node dui[1000];
int se(int a)
{
    if(a==1)
        return 2;
    else 
        return 1;
}
int bfs(int x)
{
    int tou=0;
    int wei=1;
    dui[tou].x=x;
    while(tou<wei)
    {
        for(int i=1;i<=N;i++)
        {
            if(map[dui[tou].x][i]==1)
            {
                if(vist[i]!=0)
                {
                    if(vist[i]==vist[dui[tou].x])
                        return 0;
                }
                else if(vist[i]==0)
                {
                    vist[i]=se(vist[dui[tou].x]);
                    dui[wei++].x=i;
                }
            }
        }
        tou++;
    }
    return 1;
}
int main()
{
    freopen("in.txt","r",stdin);
    while(scanf("%d",&N)!=EOF)
    {
        int a;
        int b;
        int c; 
        scanf("%d",&c);
        for(int i=0;i<c;i++)
        {
            scanf("%d%d",&a,&b);
            map[a][b]=1;
            map[b][a]=1;
        }
        vist[1]=1;
        if(bfs(1))
        {
            for(int i=1;i<=N;i++)
                if(vist[i]==1)
                printf("%d ",i);
            printf("\n");
        }
        else
            printf("NO\n");
    }

    return 0;
}

5 5
1 2
1 3
2 5
3 5
2 4
输出涂1的点
第一个5是几个点二个是几个连接的底下是连着的,从第一个开始涂1

 

转载于:https://www.cnblogs.com/liunx1109/p/6382191.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值