提交记录 4374


用户 题目 状态 得分 用时 内存 语言 代码长度
Dof noi18a. 【NOI2018】归程 Accepted 100 1.489 s 79720 KB C++ 3.02 KB
提交时间 评测时间
2018-07-22 11:20:16 2020-07-31 22:56:52
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>

typedef long long LL;
const int N = 600005, INF = 2e9 + 7, LOG = 21;

int tc, n, m, Qi, k, s;
int dis[N], flg[N], val[N], mdi[N], gr[LOG][N];
std::priority_queue<std::pair<int, int> > Q;

inline void Read(int &x) {
    x = 0; static char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
}

struct Edge {
    int u, v, a;
    inline friend bool operator < (Edge a, Edge b) {
        return a.a > b.a;
    }
} e[N];

int yun, las[N], to[N << 1], pre[N << 1], wi[N << 1];
inline void Add(int a, int b, int c = 0) {
    to[++yun] = b; wi[yun] = c; pre[yun] = las[a]; las[a] = yun;
}
void Gragh_clear() {
    memset(gr, 0, sizeof gr);
    memset(las, 0, sizeof las);
    yun = 0;
}

namespace DSU {
    int fa[N];
    void Init() {
        for (int i = 1; i <= n + m; ++i) {
            fa[i] = i;
            if (i <= n) mdi[i] = dis[i], val[i] = -1;
        }
    }
    int Seek(int x) {
        return (x == fa[x])? (x) : (fa[x] = Seek(fa[x]));
    }
    void Merge(int x, int y) {
        fa[Seek(y)] = x;
    }
}

void Dij() {
    for (int i = 1; i <= n; ++i) {
        dis[i] = INF; flg[i] = 0;
    }
    dis[1] = 0;
    Q.push(std::make_pair(0, 1));
    for (; !Q.empty(); ) {
        int x = Q.top().second; Q.pop();
        if (flg[x]) continue;
        flg[x] = 1;
        for (int i = las[x]; i; i = pre[i]) {
            if (dis[to[i]] > dis[x] + wi[i]) {
                dis[to[i]] = dis[x] + wi[i];
                Q.push(std::make_pair(-dis[to[i]], to[i]));
            }
        }
    }
}

int main() {
    scanf("%d", &tc);
    for (; tc; --tc) {
        scanf("%d%d", &n, &m);
        Gragh_clear();
        for (int i = 1, x, y, a, l; i <= m; ++i) {
            //scanf("%d%d%d%d", &x, &y, &l, &a);
            Read(x); Read(y); Read(l); Read(a);
            Add(x, y, l); Add(y, x, l);
            e[i] = (Edge) { x, y, a };
        }
        Dij(); DSU::Init();
        
        std::sort(e + 1, e + 1 + m);
        for (int i = 1; i <= m; ++i) {
            int x = DSU::Seek(e[i].u), y = DSU::Seek(e[i].v);
            if (x == y) continue;
            val[i + n] = e[i].a;
            mdi[i + n] = std::min(mdi[x], mdi[y]);
            DSU::Merge(i + n, x); DSU::Merge(i + n, y);
            gr[0][x] = gr[0][y] = i + n;
        }
        
        for (int i = 1; i < LOG; ++i) {
            for (int j = 1; j <= n + m; ++j) {
                if (gr[i - 1][j]) gr[i][j] = gr[i - 1][gr[i - 1][j]];
            }
        }
        
        scanf("%d%d%d", &Qi, &k, &s);
        for (int x, a, lans = 0; Qi; --Qi) {
            //scanf("%d%d", &x, &a);
            Read(x); Read(a);
            x = (x + (LL) k * lans - 1) % n + 1;
            a = (a + (LL) k * lans) % (s + 1);
            for (int i = LOG - 1; ~i; --i) {
                if (gr[i][x] && val[gr[i][x]] > a) x = gr[i][x];
            }
            printf("%d\n", mdi[x]);
            lans = mdi[x];
        }
    }
    
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #17.8 ms50 MB + 408 KBAcceptedScore: 5

Testcase #27.824 ms50 MB + 424 KBAcceptedScore: 5

Testcase #37.974 ms50 MB + 436 KBAcceptedScore: 5

Testcase #48.101 ms50 MB + 436 KBAcceptedScore: 5

Testcase #511.312 ms50 MB + 660 KBAcceptedScore: 5

Testcase #6710.863 ms74 MB + 52 KBAcceptedScore: 5

Testcase #710.425 ms50 MB + 556 KBAcceptedScore: 5

Testcase #810.432 ms50 MB + 560 KBAcceptedScore: 5

Testcase #910.436 ms50 MB + 556 KBAcceptedScore: 5

Testcase #10530.865 ms65 MB + 932 KBAcceptedScore: 5

Testcase #11532.312 ms65 MB + 936 KBAcceptedScore: 5

Testcase #12740.445 ms74 MB + 868 KBAcceptedScore: 5

Testcase #13739.917 ms74 MB + 780 KBAcceptedScore: 5

Testcase #14739.38 ms74 MB + 212 KBAcceptedScore: 5

Testcase #1511.855 ms50 MB + 664 KBAcceptedScore: 5

Testcase #1611.85 ms50 MB + 668 KBAcceptedScore: 5

Testcase #17740.635 ms74 MB + 428 KBAcceptedScore: 5

Testcase #18739.889 ms74 MB + 720 KBAcceptedScore: 5

Testcase #191.489 s77 MB + 872 KBAcceptedScore: 5

Testcase #201.488 s77 MB + 364 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-13 16:08:34 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠