提交记录 5643


用户 题目 状态 得分 用时 内存 语言 代码长度
AcFunction noi18a. 【NOI2018】归程 Accepted 100 1.661 s 255112 KB C++11 3.74 KB
提交时间 评测时间
2018-09-01 17:28:15 2020-08-01 00:21:07
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
 
using namespace std;
#define int long long
const int MAXN = 800800;
const int MAXM = 800800;
long long T, n, m, q, k, s, cnt, tot, fa[MAXN], dis[MAXN], h[MAXN], Min[MAXN], vis[MAXN], dp[MAXN][25];
long long Q[MAXN], hh, tt, flag[MAXN];
struct edge1 {
    long long v, w;
    edge1 *next;
}pool[MAXM ], *head[MAXN];
struct edge2 {
    int u, v, l;
    bool operator < (const edge2& _e) const {
        return l > _e.l;
    }
}e[MAXM];
struct node {
    int id, d;
    bool operator < (const node&x) const {
        return d > x.d;
    }
}tmp;
priority_queue <node> QQ;
inline void init() {
    cnt = 0; tot = n;
    memset(dis, 111, sizeof(dis));
    memset(Min, 111, sizeof(Min));
    memset(dp, 0, sizeof(dp));
    memset(h, 0, sizeof(h));
    memset(Q, 0, sizeof(Q));
    memset(vis, 0, sizeof(vis));
    memset(flag, 0, sizeof(flag));
    for(int i = 1; i <= MAXN; i++) 
        head[i] = NULL, fa[i] = i, e[i].u = e[i].v = e[i].l = 0;
}
inline void addedge(int u, int v, int w) {
    edge1 *p = &pool[++cnt], *q = &pool[++cnt];
    p->v = v, p->w = w, p->next = head[u], head[u] = p;
    q->v = u, q->w = w, q->next = head[v], head[v] = q;
}
inline int find(int x) {
    if(x == fa[x]) return x;
    else return fa[x] = find(fa[x]);
}
inline void spfa() {
    memset(flag, 0, sizeof(flag));
    hh = tt = 0;
    Q[++tt] = 1, dis[1] = 0; flag[1] = 1;
    while(hh <= tt) {
        int tmp = Q[hh++]; flag[tmp] = 0;
        for(edge1 *p = head[tmp]; p; p = p->next) {
            int v = p->v;
            if(dis[v] > dis[tmp] + p->w) {
                dis[v] = dis[tmp] + p->w;
                if(!flag[v]) Q[++tt] = v, flag[v] = 1;
            }
        }
    } 
}
inline void dijkstra()
{
    int u, v;
    dis[1] = 0, tmp.d = 0, tmp.id = 1, QQ.push(tmp);
    while(!QQ.empty())
    {
        tmp = QQ.top(); QQ.pop();
        if(dis[u = tmp.id] < tmp.d) continue;
        for(edge1 *p = head[u]; p; p = p->next)
            if(dis[v = (p->v)] > dis[u] + p->w)
            {
                dis[v] = dis[u] + p->w;
                tmp.id = v, tmp.d = dis[v], QQ.push(tmp);
            }
    }
}
inline void build_kruskal() {
    sort(e + 1, e + m + 1); tot = n;
    for(int i = 1; i <= MAXN; i++) head[i] = NULL; cnt = 0;
    for(int i = 1; i <= n; i++) fa[i] = i;
    for(int i = 1; i <= m; i++) {
        int x = find(e[i].u), y = find(e[i].v);
        if(x == y) continue;  
        h[++tot] = e[i].l;
        fa[x] = fa[y] = fa[tot] = tot;
        addedge(tot, x, 0), addedge(tot, y, 0);
    }
}
inline void dfs(int u) {
    Min[u] = dis[u]; vis[u] = 1;
    for(edge1 *p = head[u]; p; p = p->next) {
        int v = p->v;
        if(vis[v]) continue;
        vis[v] = 1; dp[v][0] = u;
        dfs(v); Min[u] = min(Min[u], Min[v]);
    }
}
#undef int
int main()
{
    scanf("%lld", &T);
    while(T--) {
        scanf("%d%d", &n, &m); init();
        for(int i = 1; i <= m; i++) {
            int u, v, w, l;
            scanf("%d%d%d%d", &u, &v, &w, &l);
            addedge(u, v, w);
            e[i].u = u, e[i].v = v, e[i].l = l; 
        }
        dijkstra();
        build_kruskal();
        dfs(tot);
        for(int i = 1; (1 << i) <= tot; i++)
            for(int j = 1; j <= tot; j++)
                dp[j][i] = dp[dp[j][i - 1]][i - 1];
        scanf("%lld%lld%lld", &q, &k, &s);
        long long last = 0;
        for(int i = 1; i <= q; i++) {
            long long v, p;
            scanf("%lld%lld", &v, &p);
            v = (v + k * last - 1) % n + 1;
            p = (p + k * last) % (s + 1);
            for(int j = 22; j >= 0; j--)
                if(dp[v][j] && h[dp[v][j]] > p)
                    v = dp[v][j];
            printf("%lld\n", last = Min[v]);
        }
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #139.528 ms219 MB + 1004 KBAcceptedScore: 5

Testcase #239.547 ms219 MB + 1008 KBAcceptedScore: 5

Testcase #339.673 ms219 MB + 1020 KBAcceptedScore: 5

Testcase #439.817 ms220 MBAcceptedScore: 5

Testcase #543.773 ms220 MB + 224 KBAcceptedScore: 5

Testcase #6936.102 ms241 MB + 188 KBAcceptedScore: 5

Testcase #742.981 ms220 MB + 192 KBAcceptedScore: 5

Testcase #843.006 ms220 MB + 200 KBAcceptedScore: 5

Testcase #942.995 ms220 MB + 196 KBAcceptedScore: 5

Testcase #10804.911 ms242 MB + 688 KBAcceptedScore: 5

Testcase #11805.269 ms242 MB + 696 KBAcceptedScore: 5

Testcase #121.017 s245 MB + 668 KBAcceptedScore: 5

Testcase #131.016 s245 MB + 672 KBAcceptedScore: 5

Testcase #141.016 s245 MB + 696 KBAcceptedScore: 5

Testcase #1544.34 ms220 MB + 248 KBAcceptedScore: 5

Testcase #1644.314 ms220 MB + 252 KBAcceptedScore: 5

Testcase #171.017 s245 MB + 672 KBAcceptedScore: 5

Testcase #181.016 s245 MB + 672 KBAcceptedScore: 5

Testcase #191.656 s249 MB + 116 KBAcceptedScore: 5

Testcase #201.661 s249 MB + 136 KBAcceptedScore: 5


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