#include<cstdio>
#include<map>
#include<cstring>
#include<queue>
using namespace std;
const int MAXN = 1e5 + 10, INF = 1e9 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, lastans;
struct Edge {
int u, v, l, a, t, nxt;
}E[MAXN];
int head[MAXN], num = 1;
int dis[MAXN], vis[MAXN];
void init() {
memset(head, -1, sizeof(head));
num = 1;
memset(vis, 0, sizeof(vis));
lastans = 0;
}
void AddEdge(int x, int y, int z, int GG) {
E[num] = (Edge){x, y, z, GG, 0, head[x]};
head[x] = num++;
}
void SPFA(int S) {
memset(dis, 0x3f, sizeof(dis));
dis[S] = 0;
queue<int> q; q.push(S);
while(!q.empty()) {
int p = q.front(); q.pop(); vis[p] = 0;
for(int i = head[p]; i != -1; i = E[i].nxt) {
int to = E[i].v;
if(dis[to] > dis[p] + E[i].l) {
dis[to] = dis[p] + E[i].l;
if(!vis[to])
q.push(to), vis[to] = 1;
}
}
}
}
void dfs(int now, int hi, int ti) {
vis[now] = ti;
lastans = min(lastans, dis[now]);
for(int i = head[now]; i != -1; i = E[i].nxt) {
int to = E[i].v;
if(vis[to] == ti) continue;
if(E[i].a <= hi) continue;
dfs(to, hi, ti);
}
}
int main() {
int QwQ = read();
while(QwQ--) {
init();
N = read(); M = read();
for(int i = 1; i <= M; i++) {
int x = read(), y = read(), z = read(), GG = read();
AddEdge(x, y, z, GG);
AddEdge(y, x, z, GG);
}
SPFA(1);
int Q = read(), K = read(), S = read();
for(int i = 1; i <= Q; i++) {
int v = read(), p = read();
v = (v + K * lastans - 1) % N + 1;
p = (p + K * lastans) % (S + 1);
lastans = INF; dfs(v, p, i);
printf("%d\n", lastans);
}
}
return 0;
}
/*
1
4 3
1 2 50 1
2 3 100 2
3 4 50 1
5 0 2
3 0
2 1
4 1
3 1
3 2
*/
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 152.94 us | 1 MB + 172 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 170.09 us | 1 MB + 176 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 293.86 us | 1 MB + 184 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 447.47 us | 1 MB + 196 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 27.011 ms | 1 MB + 432 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 2.783 ms | 3 MB + 76 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #7 | 40.965 ms | 1 MB + 352 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 39.702 ms | 1 MB + 356 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 40.397 ms | 1 MB + 352 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 3.846 ms | 3 MB + 80 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #11 | 3.869 ms | 3 MB + 468 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #12 | 3.691 ms | 3 MB + 80 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #13 | 3.696 ms | 3 MB + 76 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #14 | 4 s | 3 MB + 468 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #15 | 194.006 ms | 1 MB + 452 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #16 | 195.026 ms | 1 MB + 452 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #17 | 3.72 ms | 3 MB + 472 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #18 | 3.696 ms | 3 MB + 88 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #19 | 4 s | 3 MB + 464 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #20 | 3.693 ms | 3 MB + 76 KB | Runtime Error | Score: 0 | 显示更多 |