A - 搜索

A - 搜索
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

在古老的魔兽传说中,有两个军团,一个叫天灾,一个叫近卫。在他们所在的地域,有n个隘口,编号为1..n,某些隘口之间是有通道连接的。其中近卫军团在1号隘口,天灾军团在n号隘口。某一天,天灾军团的领袖巫妖王决定派兵攻打近卫军团,天灾军团的部队如此庞大,甚至可以填江过河。但是巫妖王不想付出不必要的代价,他想知道在不修建任何通道的前提下,部队是否可以通过隘口及其相关通道到达近卫军团展开攻击;如果可以的话,最少需要经过多少通道。由于n的值比较大(n<=100000),于是巫妖王找到了擅长编程的你 =_=,请你帮他解决这个问题,否则就把你吃掉变成他的魔法。为了拯救自己,赶紧想办法吧。

Input

输入包含多组,每组格式如下。
第一行包含两个整数n(n <= 100000),m(m <= 200000)(分别代表n个隘口,这些隘口之间有m个通道)。
下面m行每行包含两个整数a,b;表示从a出发有一条通道到达b隘口(注意:通道是双向的)。

Output

如果天灾军团可以不修建任何通道就到达1号隘口,那么输出最少经过多少通道,否则输出NO。

Sample Input

2 1
1 2
2 1
2 1

Sample Output

1
1

Hint



#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>

using namespace std;

struct node
{
    int x,y;
    int next;
} q[1000001];

struct node1
{
    int x;
    int count;
} qq[1000010];

int head[1000001];
int v[1000001];
int t = 0;
void init()
{
    t = 0;
    memset(head,-1,sizeof(head));
}

void add(int xx,int yy)
{
    q[t].x = xx;
    q[t].y = yy;
    q[t].next = head[xx];
    head[xx] = t;
    t++;
}

int n,m;

void BFS()
{
    memset(v,0,sizeof(v));
    int s = 0,e = 0;
    struct node1 tt,ff;
    tt.x = 1;
    tt.count = 0;
    v[tt.x] = 1;
    qq[e++] = tt;
    while(s<e)
    {
        tt = qq[s++];
        if(tt.x == n)
        {
            printf("%d\n",tt.count);
            return ;
        }
        int j;
        for(j=head[tt.x]; j!=-1; j=q[j].next)
        {
            if(v[q[j].y] == 0)
            {
                v[q[j].y] = 1;
                ff.count = tt.count + 1;
                ff.x = q[j].y;
                qq[e++] = ff;
            }
        }

    }
    printf("NO\n");
}

int main()
{
    int i,j;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        init();
        int x,y;
        for(i=0; i<m; i++)
        {
            scanf("%d%d",&x,&y);
            add(x,y);
            add(y,x);
        }
        BFS();
    }
    return 0;
}


a-select 是一个基于 Vue.js 的自定义搜索组件,可以方便地集成到你的项目中。你可以使用 a-select 来实现自定义的搜索功能,例如搜索框下拉列表中的选项、搜索结果的展示等。以下是使用 a-select 实现自定义搜索的步骤: 1. 安装 a-select 你可以使用 npm 或 yarn 安装 a-select: ``` npm install a-select --save ``` 或者 ``` yarn add a-select ``` 2. 引入 a-select 在你的项目中引入 a-select 组件: ```javascript import ASelect from 'a-select' ``` 3. 使用 a-select 在你的 Vue 组件中使用 a-select: ```html <template> <div> <a-select v-model="selected" :options="options" :loading="loading" @search="handleSearch" /> </div> </template> <script> import ASelect from 'a-select' export default { components: { ASelect }, data() { return { selected: '', options: [], loading: false } }, methods: { handleSearch(query) { this.loading = true // 在这里处理搜索逻辑,例如从服务器获取数据并更新 options setTimeout(() => { this.loading = false this.options = [ { value: 'apple', label: '苹果' }, { value: 'banana', label: '香蕉' }, { value: 'orange', label: '橙子' } ] }, 1000) } } } </script> ``` 在这个例子中,我们使用了 a-select 组件的 `v-model` 属性来绑定选中的值,`options` 属性来设置下拉列表中的选项,`loading` 属性来设置是否显示加载中的状态,`@search` 事件来处理搜索逻辑。当用户在搜索框中输入文字时,a-select 会触发 `@search` 事件,并将输入的查询字符串作为参数传递给事件处理函数 `handleSearch`。在 `handleSearch` 函数中,我们可以根据查询字符串从服务器获取数据,并更新 `options` 属性以更新下拉列表中的选项。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶孤心丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值