#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;
typedef long long LL;
const int N = 2e5 + 10, M = 8e5 + 10, INF = 0x3f3f3f3f;
struct node
{
int u, v, l, a;
} e[M], Q[N >> 1];
int ans[N], fa[N], Dis[N], dis[N], fst[N], wei[M], nxt[M],
to[M], E = 1, vis[N], level[M];
int getfa(int rt)
{
return fa[rt] == rt ? rt : fa[rt] = getfa(fa[rt]);
}
void add(int u, int v, int w, int l)
{
to[++E] = v, nxt[E] = fst[u], fst[u] = E, wei[E] = w, level[E] = l;
}
bool cmp(node x, node y)
{
return x.a > y.a;
}
priority_queue<P, vector<P>, greater<P> > h;
void Dij(int s)
{
memset(dis, INF, sizeof dis);
h.push(P(0, s));
while (!h.empty())
{
P tmp = h.top(); h.pop();
int u = tmp.se;
if (vis[u]) continue;
vis[u] = 1, dis[u] = tmp.fi;
for (int i = fst[u]; i != -1; i = nxt[i]) if (!vis[to[i]])
{
h.push(P(dis[u] + wei[i], to[i]));
}
}
}
int dfs(int rt, int x)
{
int ret = dis[rt];
vis[rt] = 1;
for (int i = fst[rt]; i != -1; i = nxt[i]) if (!vis[to[i]] && level[i] > x)
{
ret = min(dfs(to[i], x), ret);
}
return ret;
}
int main()
{
int n, m, q, k, s, T;
scanf("%d", &T);
while (T--)
{
memset(fst, -1, sizeof fst);
memset(vis, 0, sizeof vis); E = 0;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
{
scanf("%d%d%d%d", &e[i].u, &e[i].v, &e[i].l, &e[i].a);
add(e[i].u, e[i].v, e[i].l, e[i].a);
add(e[i].v, e[i].u, e[i].l, e[i].a);
}
Dij(1);
scanf("%d%d%d", &q, &k, &s);
if (k == 0)
{
sort(e + 1, e + m + 1, cmp);
for (int i = 1; i <= n; i++) fa[i] = i, Dis[fa[i]] = dis[i];
int pos = 1;
for (; pos <= m && e[pos].a > s; pos++)
{
int fv = getfa(e[pos].v), fu = getfa(e[pos].u);
Dis[fv] = min(Dis[fv], Dis[fu]);
fa[fu] = fv;
}
for (int i = 1; i <= q; i++)
scanf("%d%d", &Q[i].u, &Q[i].a), Q[i].l = i;
sort(Q + 1, Q + q + 1, cmp);
for (int i = 1; i <= q; i++)
{
s = Q[i].a;
for (; pos <= m && e[pos].a > s; pos++)
{
int fv = getfa(e[pos].v), fu = getfa(e[pos].u);
Dis[fv] = min(Dis[fv], Dis[fu]);
fa[fu] = fv;
}
// for (int j = 1; j <= n; j++) printf("%d ", getfa(j));
// puts("");
ans[Q[i].l] = Dis[getfa(Q[i].u)];
// printf("%d\n", pos);
}
for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}
else
{
int b, x, las = 0;
if (n <= 1500 && m <= 4000 && q <= 2000)
{
for (int i = 1; i <= q; i++)
{
memset(vis, 0, sizeof vis);
scanf("%d%d", &b, &x);
b = (b + las - 1) % n + 1;
x = (x + las) % (s + 1);
printf("%d\n", las = dfs(b, x));
}
}
else puts("Not Yet!");
}
}
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 323.42 us | 2 MB + 344 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 345.01 us | 2 MB + 368 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 485.69 us | 2 MB + 376 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 618.55 us | 2 MB + 384 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 4.272 ms | 2 MB + 644 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 543.928 ms | 25 MB + 868 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 3.263 ms | 2 MB + 520 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 3.295 ms | 2 MB + 524 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 3.283 ms | 2 MB + 520 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 300.711 ms | 17 MB + 480 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #11 | 41.658 ms | 11 MB + 512 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #12 | 643.533 ms | 25 MB + 440 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #13 | 644.84 ms | 25 MB + 436 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 645.028 ms | 25 MB + 448 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 284.782 ms | 2 MB + 668 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #16 | 284.535 ms | 2 MB + 668 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #17 | 128.849 ms | 20 MB + 856 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #18 | 128.358 ms | 20 MB + 860 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #19 | 128.089 ms | 20 MB + 856 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #20 | 128.758 ms | 20 MB + 856 KB | Runtime Error | Score: 0 | 显示更多 |