//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll long long
#define pb push_back
#define mp std::make_pair
#define orz 1000000007
#define fi first
#define se second
//using namespace std;
int n,m,q,k,s,la,d[200005],cnt,ans[400005],le[400005],pa[200005],f[400005][20];
std::pair<int,std::pair<int,int> >p[400005];
std::vector<int> v[200005],e[200005];
int get(int x){return x==pa[x]?x:pa[x]=get(pa[x]);}
int main(){
int _;
scanf("%d",&_);
while(_--){
la=0;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;++i){
int x,y,z,l;
scanf("%d%d%d%d",&x,&y,&z,&l);
p[i]=mp(-l,mp(x,y));
v[x].pb(y),v[y].pb(x);
e[x].pb(z),e[y].pb(z);
}
memset(d,-1,sizeof(d));
d[1]=0;
std::priority_queue<std::pair<int,int> >pq;
pq.push(mp(0,1));
while(!pq.empty()){
int x=pq.top().se,y=-pq.top().fi;
pq.pop();
if(d[x]!=y) continue;
for(int i=0;i<v[x].size();++i){
if(d[v[x][i]]==-1||d[v[x][i]]>y+e[x][i]){
d[v[x][i]]=y+e[x][i];
pq.push(mp(-d[v[x][i]],v[x][i]));
}
}
}
sort(p+1,p+m+1);
for(int i=1;i<=n;++i)pa[i]=i,ans[i]=d[i],le[i]=orz;
cnt=n;
for(int i=1;i<=m;++i){
int x=p[i].se.fi,y=p[i].se.se;
int X=get(x),Y=get(y);
if(X==Y) continue;
++cnt;
ans[cnt]=std::min(ans[X],ans[Y]);
le[cnt]=-p[i].fi;
pa[X]=pa[Y]=pa[cnt]=cnt;
f[X][0]=f[Y][0]=cnt;
}
for(int i=0;i<18;++i){
for(int j=1;j<=cnt;++j)f[j][i+1]=f[f[j][i]][i];
}
scanf("%d%d%d",&q,&k,&s);
while(q--){
int x,y;
scanf("%d%d",&x,&y);
x=(x+k*1ll*la-1ll)%n+1;
y=(y+k*1ll*la)%(s+1);
for(int i=18;i>=0;--i){
if(f[x][i]&&le[f[x][i]]>y)x=f[x][i];
}
la=ans[x];
printf("%d\n",la);
}
}
//system("pause");
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 1.697 ms | 9 MB + 992 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 1.726 ms | 9 MB + 1000 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #3 | 1.931 ms | 9 MB + 1016 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #4 | 2.089 ms | 10 MB + 12 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #5 | 7.288 ms | 10 MB + 616 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #6 | 1.263 s | 85 MB + 276 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #7 | 5.377 ms | 10 MB + 460 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #8 | 5.365 ms | 10 MB + 460 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #9 | 5.388 ms | 10 MB + 460 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #10 | 963.305 ms | 73 MB + 280 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #11 | 942.678 ms | 73 MB + 348 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #12 | 1.322 s | 86 MB + 1016 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #13 | 1.324 s | 86 MB + 824 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #14 | 1.321 s | 86 MB + 224 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #15 | 7.367 ms | 10 MB + 628 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #16 | 7.39 ms | 10 MB + 628 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #17 | 1.325 s | 86 MB + 568 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #18 | 1.325 s | 86 MB + 848 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #19 | 1.875 s | 89 MB + 196 KB | Wrong Answer | Score: 0 | 显示更多 |
| Testcase #20 | 1.875 s | 89 MB + 32 KB | Wrong Answer | Score: 0 | 显示更多 |