提交记录 6762


用户 题目 状态 得分 用时 内存 语言 代码长度
GKxx noi18a. 【NOI2018】归程 Accepted 100 1.836 s 82188 KB C++ 3.93 KB
提交时间 评测时间
2018-11-04 19:15:18 2020-08-01 00:49:51
#include <cctype>
#include <cstdio>
#include <climits>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>

template <typename T> inline void read(T& t) {
    int f = 0, c = getchar(); t = 0;
    while (!isdigit(c)) f |= c == '-', c = getchar();
    while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
    if (f) t = -t;
}
template <typename T> void write(T x) {
    if (x < 0) x = -x, putchar('-');
    if (x > 9) write(x / 10);
    putchar(x % 10 + 48);
}
template <typename T> void writeln(T x) {
    write(x);
    puts("");
}
template <typename T> inline bool chkMin(T& x, const T& y) { return y < x ? (x = y, true) : false; }
template <typename T> inline bool chkMax(T& x, const T& y) { return x < y ? (x = y, true) : false; }
#ifdef WIN32
#define LLIO "%I64d"
#else
#define LLIO "%lld"
#endif	// WIN32 long long
#define rep(I, A, B) for (int I = (A); I <= (B); ++I)
#define dwn(I, A, B) for (int I = (A); I >= (B); --I)
#define erp(I, X) for (int I = head[X]; I; I = next[I])

const int maxn = 4e5 + 207, inf = INT_MAX;
struct Edge {
    int x, y, l, h;
    Edge(int f, int t, int len, int hei)
        : x(f), y(t), l(len), h(hei) {}
    Edge() : x(0), y(0), l(0), h(0) {}
};
Edge e[maxn];
struct Graph {
    int v[maxn << 1], len[maxn << 1], hei[maxn << 1], next[maxn << 1], head[maxn];
    int tot;
    void ae(int x, int y, int l, int h) {
        v[++tot] = y; len[tot] = l; hei[tot] = h; next[tot] = head[x]; head[x] = tot;
    }
};
Graph G, T;
int fa[maxn], height[maxn], dist[maxn], f[30][maxn];
int n, m, test, xys;

inline void clear() {
    rep(i, 1, (n << 1)) height[i] = 0;
    rep(i, 0, 25) rep(j, 1, (n << 1)) f[i][j] = 0;
}

struct CmpType {
    bool operator()(const std::pair<int, int>& lhs, const std::pair<int, int>& rhs) {
        return lhs.second > rhs.second;
    }
};
inline void dijkstra() {
    std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, CmpType> q;
    q.push(std::make_pair(1, 0));
    rep(i, 2, n) dist[i] = inf;
    while (!q.empty()) {
        std::pair<int, int> x = q.top(); q.pop();
        if (x.second != dist[x.first]) continue;
        for (int i = G.head[x.first]; i; i = G.next[i]) {
            int v = G.v[i], w = G.len[i];
            if (dist[v] > dist[x.first] + w)
                q.push(std::make_pair(v, dist[v] = dist[x.first] + w));
        }
    }
}
inline bool higher(const Edge& lhs, const Edge& rhs) {
    return lhs.h > rhs.h;
}
int findf(int x) { return fa[x] == x ? x : (fa[x] = findf(fa[x])); }
inline void kruskal() {
    rep(i, 1, (n << 1)) fa[i] = i;
    xys = n;
    std::sort(e + 1, e + m + 1, higher);
    T.tot = 0;
    rep(i, 1, (n << 1)) T.head[i] = 0;
    rep(i, 1, m) {
        int x = e[i].x, y = e[i].y, w = e[i].h;
        int fx = findf(x), fy = findf(y);
        if (fx != fy) {
            fa[fx] = fa[fy] = ++xys;
            T.ae(xys, fx, 0, 0);
            T.ae(xys, fy, 0, 0);
            height[xys] = w;
            dist[xys] = std::min(dist[fx], dist[fy]);
        }
    }
}
void dfs(int x) {
    rep(i, 1, 25) f[i][x] = f[i - 1][f[i - 1][x]];
    for (int i = T.head[x]; i; i = T.next[i]) {
        f[0][T.v[i]] = x;
        dfs(T.v[i]);
    }
}
inline int query(int v, int p) {
    dwn(i, 25, 0) if (height[f[i][v]] > p) v = f[i][v];
    return dist[v];
}

int main() {
    read(test);
    while (test--) {
        read(n); read(m);
        G.tot = 0;
        rep(i, 1, n) G.head[i] = 0;
        rep(i, 1, m) {
            int x, y, l, h;
            read(x); read(y); read(l); read(h);
            G.ae(x, y, l, h);
            G.ae(y, x, l, h);
            e[i] = Edge(x, y, l, h);
        }
        dijkstra();
        kruskal();
        dfs(xys);
        int q, k, s;
        read(q); read(k); read(s);
        int lastans = 0;
        while (q--) {
            int v, p; read(v); read(p);
            v = (v + k * lastans - 1) % n + 1;
            p = (p + k * lastans) % (s + 1);
            writeln(lastans = query(v, p));
        }
        clear();
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1888.72 us6 MB + 252 KBAcceptedScore: 5

Testcase #2912.55 us6 MB + 296 KBAcceptedScore: 5

Testcase #31.035 ms6 MB + 312 KBAcceptedScore: 5

Testcase #41.167 ms6 MB + 336 KBAcceptedScore: 5

Testcase #54.696 ms6 MB + 860 KBAcceptedScore: 5

Testcase #61.071 s73 MB + 548 KBAcceptedScore: 5

Testcase #73.986 ms6 MB + 800 KBAcceptedScore: 5

Testcase #84.061 ms6 MB + 804 KBAcceptedScore: 5

Testcase #93.994 ms6 MB + 800 KBAcceptedScore: 5

Testcase #10855.482 ms68 MB + 868 KBAcceptedScore: 5

Testcase #11857.474 ms68 MB + 876 KBAcceptedScore: 5

Testcase #12919.808 ms76 MB + 800 KBAcceptedScore: 5

Testcase #13918.373 ms76 MB + 804 KBAcceptedScore: 5

Testcase #14918.777 ms76 MB + 824 KBAcceptedScore: 5

Testcase #155.163 ms6 MB + 876 KBAcceptedScore: 5

Testcase #165.166 ms6 MB + 880 KBAcceptedScore: 5

Testcase #17918.179 ms76 MB + 804 KBAcceptedScore: 5

Testcase #18918.357 ms76 MB + 800 KBAcceptedScore: 5

Testcase #191.832 s80 MB + 244 KBAcceptedScore: 5

Testcase #201.836 s80 MB + 268 KBAcceptedScore: 5


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