CF685E Travelling Through the Snow Queen's Kingdom
题意
给定一张图,走出当前边的时间为 \(i\)。
\(q\) 次询问,问 \(s\) 是否能在 \(l \to r\) 中走到 \(t\)。
Sol
考虑将边从大到小插入图中。
注意到当前边只能对起点造成贡献。
复杂度 \(O(n \times \max\{n, m\})\)
Code
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <array>
#include <bitset>
#define int long long
#define pii pair <int, int>
using namespace std;
#ifdef ONLINE_JUDGE
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 23], *p1 = buf, *p2 = buf, ubuf[1 << 23], *u = ubuf;
#endif
int read() {
int p = 0, flg = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') flg = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
p = p * 10 + c - '0';
c = getchar();
}
return p * flg;
}
void write(int x) {
if (x < 0) {
x = -x;
putchar('-');
}
if (x > 9) {
write(x / 10);
}
putchar(x % 10 + '0');
}
#define fi first
#define se second
const int N = 1005, M = 2e5 + 5;
array <pii, M> edge;
struct Node {
int l, r, s, t;
int id;
} isl[M];
array <array <int, N>, N> f;
bitset <M> ans;
signed main() {
int n = read(), m = read(), q = read();
for (int i = 1; i <= m; i++)
edge[i].fi = read(), edge[i].se = read();
for (int i = 1; i <= q; i++) {
isl[i].l = read(), isl[i].r = read();
isl[i].s = read(), isl[i].t = read();
isl[i].id = i;
}
sort(isl + 1, isl + 1 + q, [](Node x, Node y) {return x.l > y.l;});
array <int, N> tp;
tp.fill(0x7f7f7f7f);
f.fill(tp);
int now = 1;
for (int i = m; i; i--) {
f[edge[i].fi][edge[i].se] = f[edge[i].se][edge[i].fi] = i;
for (int j = 1; j <= n; j++) f[edge[i].fi][j] = f[edge[i].se][j] = min(f[edge[i].fi][j], f[edge[i].se][j]);
while (now <= q && isl[now].l == i) {
if (f[isl[now].s][isl[now].t] <= isl[now].r)
ans[isl[now].id] = 1;
now++;
}
}
for (int i = 1; i <= q; i++)
puts((ans[i] ? "Yes" : "No"));
return 0;
}