Submission #745823

# Submission time Handle Problem Language Result Execution time Memory
745823 2023-05-21T08:21:36 Z vjudge1 Cities (BOI16_cities) C++17
15 / 100
229 ms 8384 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 = 1000;
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});
            }
        }
    }
}

vector<pii > prs = {{0, 1}, {0, 2}, {0, 3}};
vector<pii > opp_prs = {{2, 3}, {1, 3}, {1, 2}};

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(1 + n);
    for(int i = 1; i <= n; i++) {
        dijkstra(i, distances[i]);
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            for(int idx = 0; idx < 3; idx++) {
                int a = specials[prs[idx].fi], b = specials[prs[idx].se];
                int c = specials[opp_prs[idx].fi], d = specials[opp_prs[idx].se];
                int cur = 0;
                cur += distances[i][j];
                cur += distances[i][a];
                cur += distances[i][b];
                cur += distances[j][c];
                cur += distances[j][d];
                if(ans > cur) {
                    ans = cur;
                }
            }
        }
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 229 ms 8384 KB Output is correct
2 Correct 207 ms 8372 KB Output is correct
3 Correct 60 ms 8196 KB Output is correct
4 Correct 96 ms 2452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -