답안 #745786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745786 2023-05-21T07:45:21 Z vjudge1 Cities (BOI16_cities) C++17
14 / 100
437 ms 30248 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

struct edge {
    int from, to, wei;
    bool operator < (const edge &other) const {
        return wei > other.wei;
    }
};

const int maxn = 1e5;
const int inf = 1e16 + 42;

int n, k, m;
vector<edge> graph[1 + maxn];
bool special[1 + maxn];
vector<int> specials;

void dijkstra(int source, vector<int> &dist) {
    dist.assign(1 + n, -1);
   // dist[source] = 0;
    priority_queue<edge> q;
    q.push({0, source, 0});
    while(!q.empty()) {
        edge cur = q.top();
        q.pop();
        if(dist[cur.to] != -1) {
            continue;
        }
        dist[cur.to] = cur.wei;
        for(const edge &nei : graph[cur.to]) {
            if(dist[nei.to] == -1 || dist[nei.to] /*<*/> dist[cur.to] + nei.wei) {
                q.push({cur.to, nei.to, dist[cur.to] + nei.wei});
            }
        }
    }
}

void solve() {
    cin >> n >> k >> m;
    for(int i = 0; i < k; i++) {
        int x;
        cin >> x;
        special[x] = true;
        specials.pb(x);
    }
    for(int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        graph[a].pb({a, b, c});
        graph[b].pb({b, a, c});
    }
    int ans = inf;
    vector<vector<int> > distances(k);
    for(int i = 0; i < k; i++) {
        dijkstra(specials[i], distances[i]);
    }
    for(int i = 1; i <= n; i++) {
        int cur = 0;
        for(int j = 0; j < k; j++) {
            cur += distances[j][i];
        }
        ans = min(ans, cur);
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Incorrect 1 ms 2644 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 352 ms 27948 KB Output is correct
2 Correct 333 ms 28108 KB Output is correct
3 Correct 106 ms 13744 KB Output is correct
4 Correct 244 ms 30248 KB Output is correct
5 Correct 261 ms 28260 KB Output is correct
6 Correct 167 ms 30220 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 3 ms 2868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 428 ms 28880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 437 ms 29792 KB Output isn't correct
2 Halted 0 ms 0 KB -