#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
inline int read() {
int x = 0,f = 1;
char c = getchar();
while(c < '0' ||c > '9'){if(c == '-') f = -1;c = getchar();}
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
return x * f;
}
const int maxn = 1000007;
int n,m;
struct node {
int u,v,l,a,next;
} edge[maxn << 1];
int head[maxn],num = 0;
int A[maxn],k,s;
inline void add_edge(int u,int v,int l,int a) { edge[++ num].v = v;edge[num].next = head[u],head[u] = num; edge[num].l = l; edge[num].a = a; }
int q[(maxn * 2)],dis[maxn]; bool vis[maxn];
int lastans = 0;
int spfa(int x) {
int l = 0,r = 0;
memset(vis,0,sizeof vis);
memset(dis,0x3f,sizeof dis);
q[++ r] = x; vis[x] = 1; dis[x] = 0;
while(l <= r) {
int u = q[++ l];
for(int i = head[u];i;i = edge[i].next) {
int v = edge[i].v;
if(dis[v] > dis[u] + edge[i].l) {
dis[v] = dis[u] + edge[i].l;
if(!vis[v]) {q[++ r] = v,vis[v] = 1;}
}
}
vis[u] = 0;
}
}
void work1(int X) {
spfa(1);
int Q = read();int k = read(),s = read();
for(int v,p;Q --;) {
v = (read() + k * lastans - 1) % n + 1;
p = (read() + k * lastans) % (s + 1);
if(p >= X) printf("%lld\n",dis[v]),lastans = dis[v];
else puts("0"),lastans = 0;
}
}
int dad[maxn][25],h[maxn][25],deep[maxn];
void dfs(int x,int fa) {
for(int i = 0;dad[x][i];++ i) {
dad[x][i + 1] = dad[dad[x][i]][i];
h[x][i + 1] = std::min(h[x][i],h[dad[x][i]][i]);
}
for(int i = head[x];i;i = edge[i].next) {
int v = edge[i].v;
if(v == fa) continue;
dis[v] = dis[x] + edge[i].l;
h[v][0] = edge[i].a;
dad[v][0] = x;
dfs(v,x);
}
}
int Jump(int x,int p) {
for(int i = 20;i >= 0;-- i)
if(h[x][i] > p) x = dad[x][i];
return lastans = dis[x];
}
void work2() {
dfs(1,0);
int Q = read();int k = read(),s = read();
for(int v,p;Q --;) {
v = (read() + k * lastans - 1) % n + 1;
p = (read() + k * lastans) % (s + 1);
printf("%lld\n",Jump(v,p));
}
}
void init() {
lastans = 0;
n = read(),m = read(); int cnt = 0;
for(int u,v,l,a,i = 1;i <= m;++ i) {
u = read(),v = read(),l = read(),a = read();
add_edge(u,v,l,a); add_edge(v,u,l,a);
A[i] = a;
if(A[i] != A[i - 1]) cnt ++;
}
if(cnt == 1) work1(A[1]);
else if(m == n - 1) work2();
}
main() {
int t = read(); while(t --) {
memset(head,0,sizeof head); num = 0; lastans = 0;
init();
}
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 1.169 ms | 7 MB + 672 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 19.159 ms | 16 MB + 248 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #3 | 19.336 ms | 16 MB + 260 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #4 | 19.224 ms | 16 MB + 276 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #5 | 22.232 ms | 17 MB + 96 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #6 | 654.863 ms | 69 MB + 652 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #7 | 3.801 ms | 8 MB + 524 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 3.797 ms | 8 MB + 528 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 3.786 ms | 8 MB + 524 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 417.942 ms | 569 MB + 196 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #11 | 372.193 ms | 569 MB + 196 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #12 | 31.739 ms | 41 MB + 236 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #13 | 31.791 ms | 41 MB + 240 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #14 | 31.786 ms | 41 MB + 236 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #15 | 1.174 ms | 7 MB + 1020 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #16 | 1.173 ms | 7 MB + 1020 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #17 | 31.474 ms | 41 MB + 236 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #18 | 31.521 ms | 41 MB + 236 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #19 | 31.535 ms | 41 MB + 236 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #20 | 31.51 ms | 41 MB + 236 KB | Runtime Error | Score: 0 | 显示更多 |