답안 #887327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887327 2023-12-14T09:10:22 Z vjudge1 Cities (BOI16_cities) C++17
14 / 100
244 ms 19008 KB
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ll 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(5);
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 (vis[u] == false && d[idx][v] + w < d[idx][u]) {
                d[idx][u] = d[idx][v] + w;
                pq.push({-d[idx][u], u});
            }
        }
    }
}

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

    cin >> n >> k >> m;
    for (int i = 0; i < k; ++i) {
        cin >> imp[i]; --imp[i];
    }
    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;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6644 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Incorrect 1 ms 6492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 16744 KB Output is correct
2 Correct 143 ms 19008 KB Output is correct
3 Correct 45 ms 11880 KB Output is correct
4 Correct 45 ms 14576 KB Output is correct
5 Correct 130 ms 18384 KB Output is correct
6 Correct 45 ms 14672 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 244 ms 16628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 183 ms 16592 KB Output isn't correct
2 Halted 0 ms 0 KB -