提交记录 47236


用户 题目 状态 得分 用时 内存 语言 代码长度
mingjunyi noi18a. 【NOI2018】归程 Accepted 100 1.322 s 142172 KB C++17 2.97 KB
提交时间 评测时间
2026-08-20 17:46:49 2026-08-20 17:47:08
#include<bits/stdc++.h>
using namespace std;
#define int long long
int rd() {
	int x = 0, w = 1;
	char ch = 0;
	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;
}

void wt(int x) {
	static int sta[35];
	int f = 1;
	if(x < 0) f = -1,x *= f;
	int top = 0;
	do {
		sta[top++] = x % 10, x /= 10;
	} while (x);
	if(f == -1) putchar('-');
	while (top) putchar(sta[--top] + 48);
}

const int N = 400005,M = 400005;

struct edge{
int head[N<<1],nxt[M<<1],to[M<<1],val[M<<1],cnt;

edge() {memset(head,-1,sizeof(head));}

void add(int u,int v,int w) {
    nxt[cnt] = head[u];
    to[cnt] = v;
    val[cnt] = w;
    head[u] = cnt++;
}
}g,G;

struct ED{
    int x,y,a;
}E[M];

struct node{
    int x,d;
    node(int x,int d) : x(x),d(d){}
    friend bool operator < (node a,node b) {
        return a.d > b.d;
    }
};

bool cmp(ED a,ED b) {
    return a.a > b.a;
}

int n,m,dis[N<<1],mn[N<<1],fa[N<<1][21],s[N<<1],v[N<<1];
bool vis[N<<1];

void dij() {
    memset(vis,0,sizeof(vis));
    memset(dis,0x3f,sizeof(dis));
    priority_queue<node> q;
    q.emplace(node(1,0));
    dis[1] = 0;
    while(q.size()) {
        node t = q.top();
        q.pop();
        if(vis[t.x]) continue;
        vis[t.x] = true;
        for(int i = g.head[t.x];~i;i = g.nxt[i]) {
            int y = g.to[i];
            if(dis[y] > dis[t.x] + g.val[i]) {
                dis[y] = dis[t.x] + g.val[i];
                q.emplace(node(y,dis[y]));
            }
        }
    }
}

int find(int x) {
    if(s[x] ^ x) s[x] = find(s[x]);
    return s[x];
}

void dfs(int x,int f) {
    fa[x][0] = f;mn[x] = dis[x];
    for(int i = 1;i<=20;i++) fa[x][i] = fa[fa[x][i-1]][i-1];
    for(int i = G.head[x];~i;i = G.nxt[i]) {
        int y = G.to[i];
        dfs(y,x);
        mn[x] = min(mn[x],mn[y]);
        
    }
}

void kruskalTree(){
    sort(E + 1,E + m + 1,cmp);
    int now = n;
    for(int i = 1;i<=n * 3;i++) s[i] = i;
    for(int i = 1;i<=m;i++) {
        int fx = find(E[i].x),fy = find(E[i].y);
        if(fx ^ fy) {
            s[fx] = s[fy] = ++now;
            v[now] = E[i].a;
            s[now] = now;
            G.add(now,fx,1);G.add(now,fy,1);
        }
    }
    dfs(now,0);
}

void solve() {
    memset(g.head,-1,sizeof(g.head));
    g.cnt = 0;
    memset(G.head,-1,sizeof(G.head));
    G.cnt = 0;
    n = rd(),m = rd();
    for(int i = 1;i<=m;i++) {
        int x = rd(),y = rd(),l = rd(),a = rd();
        E[i].x = x;E[i].y = y;E[i].a = a;
        g.add(x,y,l);g.add(y,x,l);
    }
    dij();
    kruskalTree();
    int Q = rd(),K = rd(),S = rd();
    int last = 0;
    while(Q--) {
        int V = rd(),p = rd();
        V = (V + K * last - 1) % n + 1;
        p = (p + K * last) % (S + 1);
        for(int i = 20;i>=0;i--)
            if(fa[V][i] && v[fa[V][i]] > p) 
                V = fa[V][i];
        wt(last = mn[V]);
        putchar('\n');
    }   
}

signed main() {
    int T = rd();
    while(T--) solve();
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #13.432 ms19 MB + 132 KBAcceptedScore: 5

Testcase #23.452 ms19 MB + 160 KBAcceptedScore: 5

Testcase #33.543 ms19 MB + 188 KBAcceptedScore: 5

Testcase #43.644 ms19 MB + 220 KBAcceptedScore: 5

Testcase #56.513 ms20 MB + 96 KBAcceptedScore: 5

Testcase #6749.327 ms132 MB + 116 KBAcceptedScore: 5

Testcase #75.828 ms19 MB + 948 KBAcceptedScore: 5

Testcase #85.811 ms19 MB + 952 KBAcceptedScore: 5

Testcase #95.815 ms19 MB + 948 KBAcceptedScore: 5

Testcase #10570.971 ms119 MB + 204 KBAcceptedScore: 5

Testcase #11570.91 ms119 MB + 208 KBAcceptedScore: 5

Testcase #12842.982 ms135 MB + 368 KBAcceptedScore: 5

Testcase #13843.537 ms135 MB + 372 KBAcceptedScore: 5

Testcase #14843.045 ms135 MB + 392 KBAcceptedScore: 5

Testcase #157.171 ms20 MB + 108 KBAcceptedScore: 5

Testcase #167.159 ms20 MB + 112 KBAcceptedScore: 5

Testcase #17843.8 ms135 MB + 372 KBAcceptedScore: 5

Testcase #18843.682 ms135 MB + 372 KBAcceptedScore: 5

Testcase #191.314 s138 MB + 836 KBAcceptedScore: 5

Testcase #201.322 s138 MB + 860 KBAcceptedScore: 5


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