#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int n,m,T,q,x,y,z,zz,k,s,v0,p0,lastans,v,p,nowans;
const int N=1000000,INF=1e9;
int dis[N],vis[N],f[N],fa[N],ans[N],out[N],FA[N][20],H[N];
vector<int> son[N];
struct link
{
int top,fi[N],ne[N],la[N],to[N],l[N],h[N];
inline void clear()
{
top=0,memset(fi,0,sizeof fi),memset(ne,0,sizeof ne),memset(la,0,sizeof la),memset(to,0,sizeof to),memset(l,0,sizeof l),memset(h,0,sizeof h);
}
inline void add(int x,int y,int z,int H)
{
top++,to[top]=y,l[top]=z,h[top]=H;
if(fi[x]==0)fi[x]=top;else ne[la[x]]=top;
la[x]=top;
}
}L;
struct node
{
int id,dis;
bool operator < (const node &a) const {return a.dis < dis;}
};
priority_queue<node> que;
inline void DIJKSTRA()
{
for(int i=1;i<=n;i++)dis[i]=INF,vis[i]=0;
dis[1]=0;while(!que.empty())que.pop();
node tmp;
tmp.id=1;tmp.dis=0;que.push(tmp);
while (!que.empty())
{
int now=que.top().id;
que.pop();
if (vis[now]) continue;
vis[now]=true;
for (int i=L.fi[now];i;i=L.ne[i])
{
if (!vis[L.to[i]]&&dis[L.to[i]]>dis[now]+L.l[i])
{
dis[L.to[i]]=dis[now]+L.l[i];
tmp.id=L.to[i];tmp.dis=dis[L.to[i]];
que.push(tmp);
}
}
}
}
struct E{int x,y,l,h;}e[N];
inline bool cmp(E a,E b){return a.h>b.h;}
inline int ASK(int x){if(fa[x]==x)return x;else return fa[x]=ASK(fa[x]);}
inline int Read()
{
int x=0,f=1;char c=getchar();
while(c>'9'||c<'0') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=x*10+c-'0'; c=getchar();}
return x*f;
}
void dfs(int x)
{
for(int i=1;i<=19;i++)FA[x][i]=FA[FA[x][i-1]][i-1];
for(int i=0;i<son[x].size();i++)
{
dfs(son[x][i]);
}
}
int main()
{
T=Read();
while(T--)
{
L.clear();lastans=0;n=Read(),m=Read();
for(int i=1;i<=2*n;i++)fa[i]=i;
for(int i=1;i<=m;i++)
{
x=Read(),y=Read(),z=Read(),zz=Read();
e[i].x=x,e[i].y=y,e[i].l=z,e[i].h=zz;
L.add(x,y,z,zz),L.add(y,x,z,zz);
}
DIJKSTRA();sort(e+1,e+1+m,cmp);int tot=n;
for(int i=1;i<=n;i++)ans[i]=dis[i],H[i]=1e9;
q=Read(),k=Read(),s=Read();
for(int i=1;i<=m;i++)
{
int fx=ASK(e[i].x),fy=ASK(e[i].y);
if(fx!=fy)
{
tot++;fa[tot]=tot;fa[fx]=fa[fy]=tot;ans[tot]=min(ans[fx],ans[fy]);FA[fx][0]=FA[fy][0]=tot;
H[tot]=e[i].h;
}
}
int root;
for(int i=1;i<=tot;i++)son[i].clear();
for(int i=1;i<=tot;i++)
{
son[FA[i][0]].push_back(i);
if(FA[i][0]==i)root=i;
}
dfs(root);
while(q--)
{
scanf("%d%d",&v0,&p0);
v=(v0+k*lastans-1)%n+1;
p=(p0+k*lastans)%(s+1);
int now=v;
for(int i=19;i>=0;i--)if(H[FA[now][i]]>p)now=FA[now][i];
lastans=ans[now];
printf("%d\n",lastans);
}
}
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 5.153 ms | 45 MB + 840 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #2 | 5.163 ms | 45 MB + 848 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #3 | 5.176 ms | 45 MB + 856 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #4 | 5.196 ms | 45 MB + 868 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #5 | 5.892 ms | 46 MB + 188 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #6 | 138.658 ms | 80 MB + 616 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #7 | 5.579 ms | 46 MB + 176 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #8 | 5.49 ms | 46 MB + 176 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #9 | 5.577 ms | 46 MB + 176 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #10 | 83.46 ms | 91 MB + 616 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #11 | 83.577 ms | 91 MB + 616 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #12 | 163.357 ms | 81 MB + 860 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #13 | 163.734 ms | 81 MB + 516 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #14 | 163.098 ms | 81 MB + 856 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #15 | 6.069 ms | 46 MB + 196 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #16 | 6.082 ms | 46 MB + 204 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #17 | 163.162 ms | 81 MB + 288 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #18 | 163.483 ms | 81 MB + 476 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #19 | 163.002 ms | 81 MB + 512 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #20 | 163.208 ms | 81 MB + 508 KB | Runtime Error | Score: 0 | 显示更多 |