QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#414041#8038. Hammer to Fallsgweo8ysRE 0ms0kbC++142.0kb2024-05-18 14:32:412024-05-18 14:32:42

Judging History

你现在查看的是最新测评结果

  • [2024-05-18 14:32:42]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-05-18 14:32:41]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long LL;

const int N = 100010;
const int M = 200010;
const int B = 450;
const int p = 998244353;
const LL inf = 1e17;

int n, m, q, cnt, head[N], nxt[M], to[M], w[M], d[N];
LL a[N], b[N], f[N], mn[N];
vector < pair<LL, LL> > e[N];
multiset <LL> s[N];

inline void addedge(int u, int v, int k)
{
    to[++cnt] = v, w[cnt] = k;
    nxt[cnt] = head[u], head[u] = cnt;
}

signed main()
{
    scanf("%d%d%d", &n, &m, &q);

    for(int i = 1; i <= n; i++) scanf("%lld", a + i);

    for(int i = 1; i <= m; i++){
        int u, v, k;
        scanf("%d%d%d", &u, &v, &k);
        addedge(u, v, k), addedge(v, u, k);
        d[u]++, d[v]++;
    }
    for(int u = 1; u <= n; u++){
        for(int i = head[u]; i; i = nxt[i]){
            int v = to[i];
            if(d[v] > B) e[u].emplace_back(make_pair(v, w[i]));
        }
    }

    for(int x = 1; x <= n; x++){
        for(int i = head[x]; i; i = nxt[i]){
            int v = to[i];
            if(d[v] <= B) s[x].insert(w[i]);
        }
    }

    for(int i = 1; i <= q; i++) scanf("%lld", b + i);

    for(int i = q; i; i--){
        int x = b[i];
        if(d[x] <= B){
            LL val = inf;
            for(int j = head[x]; j; j = nxt[j]){
                int v = to[j];
                val = min(val, f[v] + w[j]);
            }
            for(int j = head[x]; j; j = nxt[j]){
                int v = to[j];
                if(d[v] > B){
                    auto u = s[v].lower_bound(f[x]);
                    s[v].erase(u);
                    s[v].insert(val + w[j]);
                }
            }
            f[x] = val;
        }
        else{
            LL val = inf;
            for(auto v : e[x]) val = min(val, f[v.first] + v.second);
            val = min(val, *s[x].begin());
            f[x] = val;
        }
    }

    LL ans = 0;
    for(int i = 1; i <= n; i++) ans += (1ll * a[i] * f[i]) % p, ans %= p;
    printf("%lld\n", ans);
    return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

3 2 2
1 1 1
2 3 10
1 2 1
3 2

output:


result: