#include <cstdio>
#include <cctype>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define clear(a) fo(ii,1,n)a[ii]=0
#define rep(i,x) for(edg *i=x; i; i=i->ne)
#define MIN(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
const int N=2e5+1,M=N<<1;
const ll inf=0x7FFFFFFF;
int T,i,n,m,u,v,a,ii,x,y,num,Q,K,S,v0,p0,p;
ll l,ans,dis[N];
struct edge
{
int u,v,a;
ll l;
}e[M];
struct edg
{
int to;
ll l;
edg *ne;
inline edg(int to,ll l,edg *ne) : to(to), l(l), ne(ne){}
}*fin[N];
template <class T> inline void read(T &x)
{
char ch=getchar(); x=0;
for(;!isdigit(ch);ch=getchar());
for(;isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch^48);
}
inline void link(int x,int y)
{
fin[x]=new edg(y,l,fin[x]);
}
struct node
{
int i; ll dis;
inline node(int _i,ll _dis){i=_i; dis=_dis;}
};
struct cmp1
{
inline bool operator ()(const node &a,const node &b){return a.dis>b.dis;}
};
priority_queue <node,vector<node>,cmp1> P;
bool vis[N];
void dijkstra()
{
while(!P.empty())P.pop(); P.push(node(1,0));
clear(vis);
memset(dis,127,sizeof dis); dis[1]=0;
while(!P.empty())
{
node t=P.top(); P.pop();
int x=t.i; ll d=t.dis;
if(vis[x]) continue;
vis[x]=1;
rep(i,fin[x])
{
y=i->to; l=i->l;
if(!vis[y]&&dis[y]>d+l)
{
dis[y]=d+l;
P.push(node(y,dis[y]));
}
}
}
}
int fa[N],fu,fv,L[N],R[N],anc[N][18],low[N][18];
ll mi[N];
inline bool cmp(edge a,edge b){return a.a>b.a;}
int gef(int x)
{
return fa[x]==x ? x : fa[x]=gef(fa[x]);
}
void kruskal()
{
sort(e+1,e+m+1,cmp);
int i;
fo(i,1,n) fa[i]=i;
fo(i,1,m)
{
u=e[i].u; v=e[i].v;
fu=gef(u);fv=gef(v);
if(fu!=fv)
{
anc[fu][0]=fa[fu]=anc[fv][0]=fa[fv]=fa[num+1]=++num;
low[fu][0]=low[fv][0]=e[i].a;
L[num]=fu; R[num]=fv;
}
}
}
void dfs(int x)
{
int i,f=anc[x][0]; mi[x]=dis[x];
fo(i,1,17)
{
if(!f) break;
low[x][i]=min(low[x][i-1],low[f][i-1]);
f=anc[x][i]=anc[f][i-1];
}
if(L[x]) dfs(L[x]), MIN(mi[x],mi[L[x]]);
if(R[x]) dfs(R[x]), MIN(mi[x],mi[R[x]]);
}
int main()
{
for(read(T);T;T--)
{
read(n); read(m);
clear(fin);
fo(i,1,m)
{
read(u), read(v), read(l), read(a);
e[i].u=u,e[i].v=v,e[i].l=l,e[i].a=a;
link(u,v); link(v,u);
}
dijkstra();
num=n; kruskal();
dfs(num);
read(Q); read(K); read(S);
fo(i,1,Q)
{
read(v0); v=(v0+K*ans-1)%n+1;
read(p0); p=(p0+K*ans)%(S+1);
fd(ii,17,0) if( anc[v][ii] && low[v][ii]>p ) v=anc[v][ii];
printf("%lld\n",ans=mi[v]);
}
}
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 205.43 us | 1 MB + 576 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 100.356 ms | 545 MB + 308 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #3 | 64.669 ms | 545 MB + 316 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #4 | 99.713 ms | 545 MB + 324 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #5 | 68.887 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #6 | 192.187 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #7 | 68.279 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #8 | 99.657 ms | 545 MB + 320 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #9 | 69.231 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #10 | 127.714 ms | 545 MB + 408 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #11 | 164.999 ms | 545 MB + 384 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #12 | 227.991 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #13 | 228.324 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #14 | 227.33 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #15 | 71.542 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #16 | 69.522 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #17 | 227.963 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #18 | 228.977 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #19 | 227.567 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #20 | 227.544 ms | 575 MB + 828 KB | Runtime Error | Score: 0 | 显示更多 |