提交记录 9534


用户 题目 状态 得分 用时 内存 语言 代码长度
M_sea noi18a. 【NOI2018】归程 Accepted 100 1.434 s 75096 KB C++ 3.00 KB
提交时间 评测时间
2019-06-01 16:35:35 2020-08-01 01:39:20
//It is made by M_sea
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=400000+10;
const int M=800000+10; //两倍空间
const int INF=0x3f3f3f3f;

struct Save_Edge { int u,v,l,a; };
struct Edge { int v,w,nxt; };
struct HeapNode { int u,d; };
struct Node { int l,a; };

bool operator <(Save_Edge a,Save_Edge b) { return a.a>b.a; }
bool operator <(HeapNode a,HeapNode b) { return a.d>b.d; }

int n,m;
Save_Edge E[M];
Edge e[M<<1];
int head[N],cnt=0;
Node p[N];
int inq[N],dis[N],fa[N],dep[N],f[20][N];

inline void clearGraph() { memset(head,0,sizeof(head)); cnt=0; }
inline void addEdge(int u,int v,int w=0) {
    e[++cnt].v=v,e[cnt].w=w,e[cnt].nxt=head[u],head[u]=cnt;
}
inline int find(int x) { return x==fa[x]?x:fa[x]=find(fa[x]); }
inline void merge(int x,int y) { x=find(x),y=find(y); if (x!=y) fa[x]=y; }
inline void Dijkstra() {
    memset(inq,0,sizeof(inq)); inq[1]=0;
    memset(dis,0x3f,sizeof(dis)); dis[1]=0;
    priority_queue<HeapNode> Q; Q.push((HeapNode){1,0});
    while (!Q.empty()) {
        int u=Q.top().u,d=Q.top().d; Q.pop(); inq[u]=0;
        for (re int i=head[u];i;i=e[i].nxt) {
            int v=e[i].v,w=e[i].w;
            if (d+w<dis[v]) {
                dis[v]=d+w;
                if (!inq[v]) Q.push((HeapNode){v,d+w});
            }
        }
    }
    for (re int i=1;i<=n;++i) p[i].l=dis[i];
}
inline void dfs(int u,int fa) {
    dep[u]=dep[fa]+1,f[0][u]=fa;
    for (re int i=1;i<=19;++i) f[i][u]=f[i-1][f[i-1][u]];
    for (re int i=head[u];i;i=e[i].nxt) {
        int v=e[i].v; dfs(v,u); p[u].l=min(p[u].l,p[v].l);
    }
}
inline void Build() { //建树
    clearGraph();
    int tot=0,cnt=n; sort(E+1,E+m+1);
    for (re int i=1;i<=(n<<1);++i) fa[i]=i;
    for (re int i=1;i<=m;++i) {
        int u=find(E[i].u),v=find(E[i].v);
        if (u!=v) {
            addEdge(++cnt,u),addEdge(cnt,v);
            merge(u,cnt),merge(v,cnt);
            p[cnt].a=E[i].a,++tot;
        }
        if (tot==n-1) break;
    }
    dfs(cnt,0);
}
inline int query(int v,int s) {
    for (re int i=19;i>=0;--i)
        if (dep[v]>(1<<i)&&p[f[i][v]].a>s) v=f[i][v];
    return p[v].l;
}

int main() {
    int T=read();
    while (T--) {
        clearGraph(); memset(f,0,sizeof(f)); memset(E,0,sizeof(E));
        n=read(),m=read();
        for (re int i=1;i<=m;++i) {
            E[i].u=read(),E[i].v=read(),E[i].l=read(),E[i].a=read();
            addEdge(E[i].u,E[i].v,E[i].l); addEdge(E[i].v,E[i].u,E[i].l);
        }
        for (re int i=n+1;i<=(n<<1);++i) p[i].l=INF;
        Dijkstra(); Build();
        int Q=read(),K=read(),S=read(),lastans=0;
        while (Q--) {
            int v=(read()+K*lastans-1)%n+1;
            int s=(read()+K*lastans)%(S+1);
            printf("%d\n",lastans=query(v,s));
        }
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #17.469 ms47 MB + 360 KBAcceptedScore: 5

Testcase #27.497 ms47 MB + 364 KBAcceptedScore: 5

Testcase #37.623 ms47 MB + 372 KBAcceptedScore: 5

Testcase #47.751 ms47 MB + 376 KBAcceptedScore: 5

Testcase #510.731 ms47 MB + 544 KBAcceptedScore: 5

Testcase #6854.977 ms65 MB + 396 KBAcceptedScore: 5

Testcase #710.171 ms47 MB + 512 KBAcceptedScore: 5

Testcase #810.144 ms47 MB + 520 KBAcceptedScore: 5

Testcase #910.163 ms47 MB + 516 KBAcceptedScore: 5

Testcase #10670.132 ms62 MB + 408 KBAcceptedScore: 5

Testcase #11671.36 ms62 MB + 416 KBAcceptedScore: 5

Testcase #12766.675 ms69 MB + 876 KBAcceptedScore: 5

Testcase #13766.067 ms69 MB + 880 KBAcceptedScore: 5

Testcase #14766.192 ms69 MB + 904 KBAcceptedScore: 5

Testcase #1511.237 ms47 MB + 568 KBAcceptedScore: 5

Testcase #1611.236 ms47 MB + 572 KBAcceptedScore: 5

Testcase #17766.433 ms69 MB + 880 KBAcceptedScore: 5

Testcase #18766.079 ms69 MB + 876 KBAcceptedScore: 5

Testcase #191.43 s73 MB + 324 KBAcceptedScore: 5

Testcase #201.434 s73 MB + 344 KBAcceptedScore: 5


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