Submission #1053080

# Submission time Handle Problem Language Result Execution time Memory
1053080 2024-08-11T08:32:34 Z manhlinh1501 Factories (JOI14_factories) C++17
0 / 100
24 ms 58972 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
const int MAXN = 5e5 + 5;
const i64 oo64 = 1e18;
using pli = pair<i64, int>;
int N, Q;
vector<pii> adj[MAXN];

namespace subtask1{

}

void Init(int N, int A[], int B[], int D[]) {
    for(int i = 0; i < N - 1; i++) {
        int u = A[i];
        int v = B[i];
        int w = D[i];
        adj[u].emplace_back(v, w);
        adj[v].emplace_back(u, w);
    }
}

i64 Query(int S, int X[], int T, int Y[]) {
    vector<i64> dist(N, oo64);
    priority_queue<pli, vector<pli>, greater<pli>> Q;
    for(int i = 0; i < S; i++) {
        int u = X[i];
        dist[u] = 0;
        Q.emplace(dist[u], u);
    }
    while(!Q.empty()) {
        pli top = Q.top();
        Q.pop();
        int u = top.second;
        if(top.first != dist[u]) continue;
        for(pii _ : adj[u]) {
            int v = _.first;
            int w = _.second;
            if(dist[v] > dist[u] + w) {
                dist[v] = dist[u] + w;
                Q.emplace(dist[v], v);
            }
        }
    }
    i64 ans = oo64;
    for(int i = 0; i < T; i++) {
        int u = Y[i];
        ans = min(ans, dist[u]);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 58968 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 23 ms 58972 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 58968 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -