Submission #887316

# Submission time Handle Problem Language Result Execution time Memory
887316 2023-12-14T09:01:14 Z vjudge1 Cities (BOI16_cities) C++17
0 / 100
246 ms 18244 KB
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ll long long 
#define int long long 
#define pb push_back
#define pii array<int, 2>
#define pli pair<ll, int>

const int N = 1e5 + 4;
const ll INF = 4ll * INT_MAX * N;

int n, k, m;
vector<int> imp;
vector<pii> g[N];

ll d[5][N];
bool vis[N];
priority_queue<pli> pq;

void dijkstra(int idx) {
    for (int i = 0; i < n; ++i) {
        d[idx][i] = INF;
        vis[i] = false;
    }
    
    pq.push({0, imp[idx]});
    d[idx][imp[idx]] = 0;

    while (pq.size() > 0) {
        int v = pq.top().S;
        pq.pop();

        if (vis[v] == true) {
            continue;
        }
        vis[v] = true;

        for (auto [u, w] : g[v]) {
            if (d[idx][v] + w < d[idx][u]) {
                d[idx][u] = d[idx][v] + w;
                pq.push({d[idx][u], u});
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k >> m;
    for (int i = 0; i < k; ++i) {
        int v;
        cin >> v; --v;
        imp.pb(v);
    }
    for (int i = 0; i < m; ++i) {
        int v, u, w;
        cin >> v >> u >> w;
        --v; --u;
        g[v].pb({u, w}); 
        g[u].pb({v, w});
    }

    for (int i = 0; i < k; ++i) {
        dijkstra(i);
    }

    ll ans = INF;
    for (int v = 0; v < n; ++v) {
        ll cand = 0;
        for (int i = 0; i < k; ++i) {
            cand += d[i][v];
        }
        ans = min(ans, cand);
    }
    cout << ans;

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Incorrect 1 ms 6492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 176 ms 18164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 246 ms 18132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 231 ms 18244 KB Output isn't correct
2 Halted 0 ms 0 KB -