답안 #367717

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
367717 2021-02-18T04:22:09 Z arujbansal Relay Marathon (NOI20_relaymarathon) C++17
100 / 100
5080 ms 82308 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;

    while (clock() < 5 * CLOCKS_PER_SEC) {
        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 5000 ms 2752 KB Output is correct
2 Correct 5000 ms 2800 KB Output is correct
3 Correct 5000 ms 2752 KB Output is correct
4 Correct 5000 ms 2748 KB Output is correct
5 Correct 5000 ms 2752 KB Output is correct
6 Correct 5000 ms 2668 KB Output is correct
7 Correct 5000 ms 2804 KB Output is correct
8 Correct 5000 ms 2924 KB Output is correct
9 Correct 5000 ms 2796 KB Output is correct
10 Correct 5000 ms 2796 KB Output is correct
11 Correct 5000 ms 2752 KB Output is correct
12 Correct 5000 ms 2752 KB Output is correct
13 Correct 5000 ms 2924 KB Output is correct
14 Correct 5000 ms 2796 KB Output is correct
15 Correct 5000 ms 2800 KB Output is correct
16 Correct 5000 ms 2668 KB Output is correct
17 Correct 5000 ms 2796 KB Output is correct
18 Correct 5000 ms 2752 KB Output is correct
19 Correct 5000 ms 2804 KB Output is correct
20 Correct 5000 ms 2668 KB Output is correct
21 Correct 5000 ms 2796 KB Output is correct
22 Correct 5000 ms 2748 KB Output is correct
23 Correct 5000 ms 2776 KB Output is correct
24 Correct 5000 ms 2752 KB Output is correct
25 Correct 5000 ms 2796 KB Output is correct
26 Correct 5000 ms 2796 KB Output is correct
27 Correct 5000 ms 2816 KB Output is correct
28 Correct 5000 ms 2924 KB Output is correct
29 Correct 5000 ms 2800 KB Output is correct
30 Correct 5000 ms 2804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5000 ms 2752 KB Output is correct
2 Correct 5000 ms 2800 KB Output is correct
3 Correct 5000 ms 2752 KB Output is correct
4 Correct 5000 ms 2748 KB Output is correct
5 Correct 5000 ms 2752 KB Output is correct
6 Correct 5000 ms 2668 KB Output is correct
7 Correct 5000 ms 2804 KB Output is correct
8 Correct 5000 ms 2924 KB Output is correct
9 Correct 5000 ms 2796 KB Output is correct
10 Correct 5000 ms 2796 KB Output is correct
11 Correct 5000 ms 2752 KB Output is correct
12 Correct 5000 ms 2752 KB Output is correct
13 Correct 5000 ms 2924 KB Output is correct
14 Correct 5000 ms 2796 KB Output is correct
15 Correct 5000 ms 2800 KB Output is correct
16 Correct 5000 ms 2668 KB Output is correct
17 Correct 5000 ms 2796 KB Output is correct
18 Correct 5000 ms 2752 KB Output is correct
19 Correct 5000 ms 2804 KB Output is correct
20 Correct 5000 ms 2668 KB Output is correct
21 Correct 5000 ms 2796 KB Output is correct
22 Correct 5000 ms 2748 KB Output is correct
23 Correct 5000 ms 2776 KB Output is correct
24 Correct 5000 ms 2752 KB Output is correct
25 Correct 5000 ms 2796 KB Output is correct
26 Correct 5000 ms 2796 KB Output is correct
27 Correct 5000 ms 2816 KB Output is correct
28 Correct 5000 ms 2924 KB Output is correct
29 Correct 5000 ms 2800 KB Output is correct
30 Correct 5000 ms 2804 KB Output is correct
31 Correct 5000 ms 2668 KB Output is correct
32 Correct 5000 ms 2796 KB Output is correct
33 Correct 5000 ms 2792 KB Output is correct
34 Correct 5000 ms 2792 KB Output is correct
35 Correct 5000 ms 2756 KB Output is correct
36 Correct 5000 ms 3052 KB Output is correct
37 Correct 5000 ms 3052 KB Output is correct
38 Correct 5000 ms 2924 KB Output is correct
39 Correct 5000 ms 5848 KB Output is correct
40 Correct 5000 ms 3564 KB Output is correct
41 Correct 5000 ms 2924 KB Output is correct
42 Correct 5000 ms 3528 KB Output is correct
43 Correct 5000 ms 2924 KB Output is correct
44 Correct 5000 ms 2924 KB Output is correct
45 Correct 5000 ms 2764 KB Output is correct
46 Correct 5000 ms 5868 KB Output is correct
47 Correct 5000 ms 3340 KB Output is correct
48 Correct 5000 ms 5868 KB Output is correct
49 Correct 5000 ms 5868 KB Output is correct
50 Correct 5000 ms 2796 KB Output is correct
51 Correct 5000 ms 2808 KB Output is correct
52 Correct 5000 ms 2792 KB Output is correct
53 Correct 5000 ms 4468 KB Output is correct
54 Correct 5000 ms 5960 KB Output is correct
55 Correct 5000 ms 2824 KB Output is correct
56 Correct 5000 ms 2768 KB Output is correct
57 Correct 5000 ms 2796 KB Output is correct
58 Correct 5000 ms 5848 KB Output is correct
59 Correct 5000 ms 2688 KB Output is correct
60 Correct 5000 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5014 ms 6372 KB Output is correct
2 Correct 5001 ms 3692 KB Output is correct
3 Correct 5044 ms 66004 KB Output is correct
4 Correct 5043 ms 33308 KB Output is correct
5 Correct 5063 ms 10232 KB Output is correct
6 Correct 5007 ms 8588 KB Output is correct
7 Correct 5080 ms 10904 KB Output is correct
8 Correct 5007 ms 6160 KB Output is correct
9 Correct 5010 ms 8228 KB Output is correct
10 Correct 5003 ms 6708 KB Output is correct
11 Correct 5064 ms 68048 KB Output is correct
12 Correct 5007 ms 7012 KB Output is correct
13 Correct 5037 ms 22088 KB Output is correct
14 Correct 5009 ms 10152 KB Output is correct
15 Correct 5031 ms 67012 KB Output is correct
16 Correct 5006 ms 5988 KB Output is correct
17 Correct 5027 ms 48892 KB Output is correct
18 Correct 5001 ms 4156 KB Output is correct
19 Correct 5035 ms 67048 KB Output is correct
20 Correct 5009 ms 9416 KB Output is correct
21 Correct 5011 ms 9364 KB Output is correct
22 Correct 5008 ms 6468 KB Output is correct
23 Correct 5003 ms 5124 KB Output is correct
24 Correct 5055 ms 57128 KB Output is correct
25 Correct 5011 ms 8140 KB Output is correct
26 Correct 5012 ms 6116 KB Output is correct
27 Correct 5006 ms 7668 KB Output is correct
28 Correct 5002 ms 4504 KB Output is correct
29 Correct 5010 ms 10404 KB Output is correct
30 Correct 5019 ms 15504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5000 ms 2752 KB Output is correct
2 Correct 5000 ms 2800 KB Output is correct
3 Correct 5000 ms 2752 KB Output is correct
4 Correct 5000 ms 2748 KB Output is correct
5 Correct 5000 ms 2752 KB Output is correct
6 Correct 5000 ms 2668 KB Output is correct
7 Correct 5000 ms 2804 KB Output is correct
8 Correct 5000 ms 2924 KB Output is correct
9 Correct 5000 ms 2796 KB Output is correct
10 Correct 5000 ms 2796 KB Output is correct
11 Correct 5000 ms 2752 KB Output is correct
12 Correct 5000 ms 2752 KB Output is correct
13 Correct 5000 ms 2924 KB Output is correct
14 Correct 5000 ms 2796 KB Output is correct
15 Correct 5000 ms 2800 KB Output is correct
16 Correct 5000 ms 2668 KB Output is correct
17 Correct 5000 ms 2796 KB Output is correct
18 Correct 5000 ms 2752 KB Output is correct
19 Correct 5000 ms 2804 KB Output is correct
20 Correct 5000 ms 2668 KB Output is correct
21 Correct 5000 ms 2796 KB Output is correct
22 Correct 5000 ms 2748 KB Output is correct
23 Correct 5000 ms 2776 KB Output is correct
24 Correct 5000 ms 2752 KB Output is correct
25 Correct 5000 ms 2796 KB Output is correct
26 Correct 5000 ms 2796 KB Output is correct
27 Correct 5000 ms 2816 KB Output is correct
28 Correct 5000 ms 2924 KB Output is correct
29 Correct 5000 ms 2800 KB Output is correct
30 Correct 5000 ms 2804 KB Output is correct
31 Correct 5000 ms 2668 KB Output is correct
32 Correct 5000 ms 2796 KB Output is correct
33 Correct 5000 ms 2792 KB Output is correct
34 Correct 5000 ms 2792 KB Output is correct
35 Correct 5000 ms 2756 KB Output is correct
36 Correct 5000 ms 3052 KB Output is correct
37 Correct 5000 ms 3052 KB Output is correct
38 Correct 5000 ms 2924 KB Output is correct
39 Correct 5000 ms 5848 KB Output is correct
40 Correct 5000 ms 3564 KB Output is correct
41 Correct 5000 ms 2924 KB Output is correct
42 Correct 5000 ms 3528 KB Output is correct
43 Correct 5000 ms 2924 KB Output is correct
44 Correct 5000 ms 2924 KB Output is correct
45 Correct 5000 ms 2764 KB Output is correct
46 Correct 5000 ms 5868 KB Output is correct
47 Correct 5000 ms 3340 KB Output is correct
48 Correct 5000 ms 5868 KB Output is correct
49 Correct 5000 ms 5868 KB Output is correct
50 Correct 5000 ms 2796 KB Output is correct
51 Correct 5000 ms 2808 KB Output is correct
52 Correct 5000 ms 2792 KB Output is correct
53 Correct 5000 ms 4468 KB Output is correct
54 Correct 5000 ms 5960 KB Output is correct
55 Correct 5000 ms 2824 KB Output is correct
56 Correct 5000 ms 2768 KB Output is correct
57 Correct 5000 ms 2796 KB Output is correct
58 Correct 5000 ms 5848 KB Output is correct
59 Correct 5000 ms 2688 KB Output is correct
60 Correct 5000 ms 2924 KB Output is correct
61 Correct 5014 ms 6372 KB Output is correct
62 Correct 5001 ms 3692 KB Output is correct
63 Correct 5044 ms 66004 KB Output is correct
64 Correct 5043 ms 33308 KB Output is correct
65 Correct 5063 ms 10232 KB Output is correct
66 Correct 5007 ms 8588 KB Output is correct
67 Correct 5080 ms 10904 KB Output is correct
68 Correct 5007 ms 6160 KB Output is correct
69 Correct 5010 ms 8228 KB Output is correct
70 Correct 5003 ms 6708 KB Output is correct
71 Correct 5064 ms 68048 KB Output is correct
72 Correct 5007 ms 7012 KB Output is correct
73 Correct 5037 ms 22088 KB Output is correct
74 Correct 5009 ms 10152 KB Output is correct
75 Correct 5031 ms 67012 KB Output is correct
76 Correct 5006 ms 5988 KB Output is correct
77 Correct 5027 ms 48892 KB Output is correct
78 Correct 5001 ms 4156 KB Output is correct
79 Correct 5035 ms 67048 KB Output is correct
80 Correct 5009 ms 9416 KB Output is correct
81 Correct 5011 ms 9364 KB Output is correct
82 Correct 5008 ms 6468 KB Output is correct
83 Correct 5003 ms 5124 KB Output is correct
84 Correct 5055 ms 57128 KB Output is correct
85 Correct 5011 ms 8140 KB Output is correct
86 Correct 5012 ms 6116 KB Output is correct
87 Correct 5006 ms 7668 KB Output is correct
88 Correct 5002 ms 4504 KB Output is correct
89 Correct 5010 ms 10404 KB Output is correct
90 Correct 5019 ms 15504 KB Output is correct
91 Correct 5031 ms 9596 KB Output is correct
92 Correct 5060 ms 76608 KB Output is correct
93 Correct 5008 ms 13040 KB Output is correct
94 Correct 5025 ms 47156 KB Output is correct
95 Correct 5001 ms 4196 KB Output is correct
96 Correct 5001 ms 4196 KB Output is correct
97 Correct 5010 ms 15328 KB Output is correct
98 Correct 5010 ms 9628 KB Output is correct
99 Correct 5009 ms 10364 KB Output is correct
100 Correct 5042 ms 81976 KB Output is correct
101 Correct 5020 ms 33056 KB Output is correct
102 Correct 5028 ms 32812 KB Output is correct
103 Correct 5029 ms 61376 KB Output is correct
104 Correct 5036 ms 64180 KB Output is correct
105 Correct 5004 ms 7224 KB Output is correct
106 Correct 5041 ms 61088 KB Output is correct
107 Correct 5020 ms 19972 KB Output is correct
108 Correct 5008 ms 12204 KB Output is correct
109 Correct 5002 ms 5476 KB Output is correct
110 Correct 5006 ms 6932 KB Output is correct
111 Correct 5011 ms 12100 KB Output is correct
112 Correct 5052 ms 81572 KB Output is correct
113 Correct 5037 ms 82308 KB Output is correct
114 Correct 5007 ms 11348 KB Output is correct
115 Correct 5042 ms 33552 KB Output is correct
116 Correct 5058 ms 73420 KB Output is correct
117 Correct 5033 ms 58900 KB Output is correct
118 Correct 5039 ms 52404 KB Output is correct
119 Correct 5033 ms 65772 KB Output is correct
120 Correct 5023 ms 39632 KB Output is correct