求助!!!90pts
查看原帖
求助!!!90pts
733626
mgcjade楼主2023/8/13 20:05
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5;

int to[2 * maxn + 5], nxt[2 * maxn + 5], hd[maxn + 5], tot;
void add(int x, int y)
{
    tot++;
    to[tot] = y;
    nxt[tot] = hd[x];
    hd[x] = tot;
}

int n, m, q;
int d[maxn + 5][2];

void bfs()
{
    int h = 0, t = 0;
    int q[maxn + 5][2];
    q[t][0] = 1, q[t][1] = 0, t++;

    while (h < t)
    {
        for (int i = hd[q[h][0]]; i; i = nxt[i])
        {
            q[t][0] = to[i], q[t][1] = q[h][1] + 1;
            if (d[to[i]][q[t][1] % 2] <= q[t][1])
                continue;
            d[to[i]][q[t][1] % 2] = q[t][1];
            t++;
        }
        h++;
    }
}

int main()
{
    

    int a, b;
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 1; i <= m; i++)
    {
        scanf("%d%d", &a, &b);
        add(a, b);
        add(b, a);
    }

    memset(d, 0x3f, sizeof(d));
    bfs();

    while (q--)
    {

        scanf("%d%d", &a, &b);

        if (d[a][b % 2] <= b)
            printf("Yes\n");
        else
            printf("No\n");
    }

    return 0;
}

求助!!!

#18,#20不对

2023/8/13 20:05
加载中...