#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
long long int h[1000005][2],tag[1000005],t,n,m,map[1000005][3],start[1000005],road[10000005][4],minroad[1000005];
int dijk()
{
h[1][0]=1;
h[1][1]=0;
for(int i=1;i<=n;i++)tag[i]=0;
tag[1]=1;
int p=1;
for(int i=1;i<=n;i++)minroad[i]=999999999999;
minroad[1]=0;
while(p>=1)
{
int u=h[1][0];
tag[u]=0;
swap(h[1][0],h[p][0]);
swap(h[1][1],h[p][1]);
int x=1;
//for(int i=1;i<=p;i++)cout<<h[i][0]<<" "<<h[i][1]<<" ";
p--;
while(x<=p)
{
if(h[x][1]>h[x*2][1] && (h[x*2][1]<h[x*2+1][1] || x*2+1>p) && x*2<=p)
{
swap(h[x][0],h[x*2][0]);
swap(h[x][1],h[x*2][1]);
x=x*2;
}
else if(h[x][1]>h[x*2+1][1] && h[x*2+1][1]<h[x*2][1] && x*2+1<=p)
{
swap(h[x][0],h[x*2+1][0]);
swap(h[x][1],h[x*2+1][1]);
x=x*2+1;
}
else break;
}
//for(int i=1;i<=p;i++)cout<<h[i][0]<<" "<<h[i][1]<<" ";
//cout<<endl;
int g=start[u];
//cout<<u<<endl;
while(g!=-1)
{
int now=map[g][0];
//cout<<now<<endl;
if(minroad[u]+map[g][1]<minroad[now])
{
minroad[now]=minroad[u]+map[g][1];
if(tag[now]==0)
{
tag[now]=1;
p++;
h[p][0]=now;
h[p][1]=minroad[now];
x=p;
while(x>0)
{
if(h[x][1]<h[x/2][1])
{
swap(h[x][0],h[x/2][0]);
swap(h[x][1],h[x/2][1]);
x=x/2;
}
else break;
}
}
}
g=map[g][2];
}
//cout<<endl;
//for(int i=1;i<=n;i++)cout<<minroad[i]<<" ";
//cout<<endl;
}
}
int main(){
freopen("return.in","r",stdin);
freopen("return.out","w",stdout);
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=1;i<=n;i++)start[i]=-1;
for(int i=0;i<m;i++)
{
cin>>road[i][0]>>road[i][1]>>road[i][2]>>road[i][3];
int x=road[i][0],y=road[i][1];
map[i*2][0]=y;
map[i*2][1]=road[i][2];
map[i*2][2]=start[x];
start[x]=i*2;
map[i*2+1][0]=x;
map[i*2+1][1]=road[i][2];
map[i*2+1][2]=start[y];
start[y]=i*2+1;
}
dijk();
//for(int i=1;i<=n;i++)cout<<minroad[i]<<" ";
long long int q,k,s;
cin>>q>>k>>s;
for(int i=1;i<=q;i++)
{
int v,p;
cin>>v>>p;
//cout<<v<<" "<<p<<endl;
if(p>=road[1][3])cout<<minroad[v]<<endl;
else cout<<"0"<<endl;
}
}
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 4 s | 48 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #2 | 4 s | 30 MB + 580 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #3 | 4 s | 30 MB + 584 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #4 | 4 s | 30 MB + 588 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #5 | 4 s | 30 MB + 736 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #6 | 4 s | 33 MB + 948 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #7 | 4 s | 30 MB + 652 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #8 | 4 s | 30 MB + 652 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #9 | 4 s | 30 MB + 652 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #10 | 174.638 ms | 39 MB + 736 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #11 | 184.007 ms | 39 MB + 736 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #12 | 4 s | 33 MB + 932 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #13 | 4 s | 33 MB + 732 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #14 | 4 s | 33 MB + 976 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #15 | 4 s | 30 MB + 736 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #16 | 4 s | 30 MB + 732 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #17 | 4 s | 33 MB + 836 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #18 | 4 s | 33 MB + 856 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #19 | 4 s | 33 MB + 832 KB | Time Limit Exceeded | Score: 0 | 显示更多 |
| Testcase #20 | 4 s | 33 MB + 788 KB | Time Limit Exceeded | Score: 0 | 显示更多 |