提交记录 6703


用户 题目 状态 得分 用时 内存 语言 代码长度
sdzwyq noi18a. 【NOI2018】归程 Accepted 100 1.275 s 66160 KB C++ 2.28 KB
提交时间 评测时间
2018-11-03 22:16:03 2020-08-01 00:48:43
#define ri register int
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int N=400005;
inline int re(){
    ri x=0,w=1;register char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*w;
}
int T,n,m,lastans,cnt,tot,q,k,s;
int last[N],dis[N],fa[N],f[N][25],H[N];
bool vis[N];
struct node{int id,d;};
struct Edge{int u,v,h;}E[N];
struct edge{int to,next,w;}e[N<<1];
bool operator <(node a,node b){return a.d>b.d;}
inline void link(ri u,ri v,ri w){
    e[++cnt]=(edge){v,last[u],w};last[u]=cnt;
    e[++cnt]=(edge){u,last[v],w};last[v]=cnt;
}
inline bool cmp(Edge a,Edge b){return a.h>b.h;}
priority_queue<node>Q;
inline void Dij(){
    memset(dis,63,sizeof(dis));
    memset(vis,0,sizeof(vis));
    dis[1]=0;Q.push((node){1,0});
    while(!Q.empty()){
        ri u=Q.top().id;Q.pop();
        if(vis[u])continue;vis[u]=1;
        for(ri i=last[u],v;i;i=e[i].next){
            v=e[i].to;
            if(dis[v]>dis[u]+e[i].w){
                dis[v]=dis[u]+e[i].w;
                Q.push((node){v,dis[v]});
            }
        }
    }
}
int find(ri x){return x==fa[x]?x:fa[x]=find(fa[x]);}
inline void Kru(){
    tot=n;
    memset(f,0,sizeof(f));
    memset(H,0,sizeof(H));
    for(ri i=1;i<(n<<1);i++)fa[i]=i;
    sort(E+1,E+m+1,cmp);
    for(ri i=1,x,y;i<=m;i++){
        x=find(E[i].u);
        y=find(E[i].v);
        if(x==y)continue;
        fa[x]=fa[y]=f[x][0]=f[y][0]=++tot;
        H[tot]=E[i].h;
        dis[tot]=min(dis[x],dis[y]);
    }
    for(ri j=1;j<=20;j++)
        for(ri i=1;i<=tot;i++)
            f[i][j]=f[f[i][j-1]][j-1];
}
inline int Query(ri x,ri h){
    for(ri i=20;i>=0;i--)
        if(f[x][i]&&H[f[x][i]]>h)
            x=f[x][i];
    return dis[x];
}
int main(){
    T=re();
    while(T--){
        lastans=0;cnt=0;
        n=re(),m=re();
        memset(last,0,sizeof(last));
        for(ri i=1,u,v,l,a;i<=m;i++){
            u=re(),v=re(),l=re(),a=re();
            E[i]=(Edge){u,v,a};
            link(u,v,l);
        }
        Dij();
        Kru();
        q=re(),k=re(),s=re();
        ri v,p;
        while(q--){
            v=(re()+k*lastans-1)%n+1;
            p=(re()+k*lastans)%(s+1);
            printf("%d\n",lastans=Query(v,p));
        }
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #16.679 ms43 MB + 140 KBAcceptedScore: 5

Testcase #26.702 ms43 MB + 148 KBAcceptedScore: 5

Testcase #36.835 ms43 MB + 156 KBAcceptedScore: 5

Testcase #46.928 ms43 MB + 160 KBAcceptedScore: 5

Testcase #59.877 ms43 MB + 328 KBAcceptedScore: 5

Testcase #6599.096 ms60 MB + 76 KBAcceptedScore: 5

Testcase #79.32 ms43 MB + 248 KBAcceptedScore: 5

Testcase #89.321 ms43 MB + 252 KBAcceptedScore: 5

Testcase #99.328 ms43 MB + 248 KBAcceptedScore: 5

Testcase #10532.809 ms54 MB + 68 KBAcceptedScore: 5

Testcase #11532.977 ms54 MB + 72 KBAcceptedScore: 5

Testcase #12751.063 ms61 MB + 692 KBAcceptedScore: 5

Testcase #13751.604 ms61 MB + 528 KBAcceptedScore: 5

Testcase #14751.06 ms60 MB + 960 KBAcceptedScore: 5

Testcase #1510.517 ms43 MB + 332 KBAcceptedScore: 5

Testcase #1610.482 ms43 MB + 336 KBAcceptedScore: 5

Testcase #17751.331 ms61 MB + 204 KBAcceptedScore: 5

Testcase #18750.984 ms61 MB + 492 KBAcceptedScore: 5

Testcase #191.269 s64 MB + 624 KBAcceptedScore: 5

Testcase #201.275 s64 MB + 124 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:29:15 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠