답안 #367716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
367716 2021-02-18T04:21:25 Z arujbansal Relay Marathon (NOI20_relaymarathon) C++17
25 / 100
5509 ms 70332 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <numeric>
#include <functional>
#include <chrono>
#include <utility>
#include <iomanip>
#include <assert.h>

using namespace std;

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

#define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rng_seed(x) mt19937 rng(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
// #define int long long

rng_init;

const int MXN = 1e5 + 5, INF = 1e9 + 5;
int N, M, K;
vector<pair<int, int>> g[MXN];

int dijkstra(const vector<int> &src, const vector<int> &sink) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;

    vector<int> dist(N, INF);

    for (const auto &x : src) {
        dist[x] = 0;
        pq.emplace(0, x);
    }

    vector<bool> finish(N, false);
    for (const auto &x : sink)
        finish[x] = true;

    while (!pq.empty()) {
        auto cur = pq.top();
        pq.pop();

        int u = cur.second, cur_dist = cur.first;
        if (cur_dist > dist[u]) continue;

        if (finish[u])
            return cur_dist;

        for (const auto &[v, wt] : g[u]) {
            int new_dist = cur_dist + wt;

            if (new_dist < dist[v]) {
                dist[v] = new_dist;
                pq.emplace(new_dist, v);
            }
        }
    }

    int ans = INF;
    for (const auto &x : sink)
        ans = min(ans, dist[x]);

    return ans;
}

void solve() {
    cin >> N >> M >> K;

    for (int i = 0; i < M; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--, v--;

        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }

    vector<int> special(K);
    for (auto &x : special) {
        cin >> x;
        x--;
    }

    int ans = INF;

    for (int iter = 0; iter < 100; iter++) {
        shuffle(all(special), rng);

        vector<int> src[2], sink[2];
        
        for (int i = 0; i < K / 2; i++)
            src[rng() % 2].push_back(special[i]);

        for (int i = K / 2; i < K; i++)
            sink[rng() % 2].push_back(special[i]);

        ans = min(ans, dijkstra(src[0], sink[0]) + dijkstra(src[1], sink[1]));
    }

    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int TC = 1;
    // cin >> TC;
    while (TC--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 4 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 3 ms 2668 KB Output is correct
7 Correct 3 ms 2668 KB Output is correct
8 Correct 3 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 3 ms 2668 KB Output is correct
13 Correct 4 ms 2668 KB Output is correct
14 Correct 4 ms 2668 KB Output is correct
15 Incorrect 4 ms 2668 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 4 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 3 ms 2668 KB Output is correct
7 Correct 3 ms 2668 KB Output is correct
8 Correct 3 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 3 ms 2668 KB Output is correct
13 Correct 4 ms 2668 KB Output is correct
14 Correct 4 ms 2668 KB Output is correct
15 Incorrect 4 ms 2668 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 5868 KB Output is correct
2 Correct 17 ms 4068 KB Output is correct
3 Correct 5509 ms 66340 KB Output is correct
4 Correct 3183 ms 35320 KB Output is correct
5 Correct 3131 ms 12492 KB Output is correct
6 Correct 854 ms 10120 KB Output is correct
7 Correct 3290 ms 13028 KB Output is correct
8 Correct 585 ms 7148 KB Output is correct
9 Correct 573 ms 9544 KB Output is correct
10 Correct 525 ms 8036 KB Output is correct
11 Correct 5299 ms 70332 KB Output is correct
12 Correct 429 ms 8480 KB Output is correct
13 Correct 3399 ms 22412 KB Output is correct
14 Correct 373 ms 9820 KB Output is correct
15 Correct 5275 ms 67284 KB Output is correct
16 Correct 626 ms 5912 KB Output is correct
17 Correct 2200 ms 48756 KB Output is correct
18 Correct 17 ms 3812 KB Output is correct
19 Correct 2790 ms 67100 KB Output is correct
20 Correct 445 ms 9740 KB Output is correct
21 Correct 976 ms 9580 KB Output is correct
22 Correct 277 ms 6884 KB Output is correct
23 Correct 38 ms 5356 KB Output is correct
24 Correct 5341 ms 57828 KB Output is correct
25 Correct 532 ms 8308 KB Output is correct
26 Correct 485 ms 6500 KB Output is correct
27 Correct 604 ms 7716 KB Output is correct
28 Correct 25 ms 4716 KB Output is correct
29 Correct 818 ms 12576 KB Output is correct
30 Correct 435 ms 17572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 4 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 3 ms 2668 KB Output is correct
7 Correct 3 ms 2668 KB Output is correct
8 Correct 3 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 3 ms 2668 KB Output is correct
13 Correct 4 ms 2668 KB Output is correct
14 Correct 4 ms 2668 KB Output is correct
15 Incorrect 4 ms 2668 KB Output isn't correct
16 Halted 0 ms 0 KB -