社区讨论
求助!!!90pts
P5663[CSP-J 2019] 加工零件参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lo1v7kx1
- 此快照首次捕获于
- 2023/10/23 03:31 2 年前
- 此快照最后确认于
- 2023/11/03 04:01 2 年前
CPP
#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不对
回复
共 3 条回复,欢迎继续交流。
正在加载回复...