답안 #684002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684002 2023-01-20T02:16:55 Z ScarletS Relay Marathon (NOI20_relaymarathon) C++17
100 / 100
1951 ms 214260 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 1, INF = 1e9;
int n;
vector<array<int, 2>> e[N];
bitset<N> is_special;

struct city_distance {
    int city, source, dist;
    bool operator<(const city_distance& rhs) const {
        return dist > rhs.dist;
    }
};

vector<city_distance> dijkstra(vector<int> sources, int threshold, int cnt) {
    priority_queue<city_distance> pq;
    vector<city_distance> v;
    vector<set<int>> vis(n + 1);
    for (int i : sources)
        pq.push({i, i, 0});
    while (!pq.empty()) {
        city_distance cur = pq.top();
        pq.pop();
        if (vis[cur.city].count(cur.source))
            continue;
        vis[cur.city].insert(cur.source);
        if (vis[cur.city].size() == cnt && is_special[cur.city]) {
            v.push_back(cur);
            if (v.size() == threshold)
                return v;
        }
        for (auto i : e[cur.city])
            if (!vis[i[0]].count(cur.source))
                pq.push({i[0], cur.source, cur.dist + i[1]});
    }
    return v;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int m, k, x, y, z, ans = INF;
    cin >> n >> m >> k;
    while (m--) {
        cin >> x >> y >> z;
        e[x].push_back({y, z});
        e[y].push_back({x, z});
    }
    vector<int> special(k), new_special;
    for (int i = 0; i < k; ++i) {
        cin >> special[i];
        is_special[special[i]] = 1;
    }
    city_distance close_pair = dijkstra(special, 1, 2)[0];
    x = close_pair.city;
    y = close_pair.source;
    is_special[x] = 0;
    is_special[y] = 0;

    // Let a = x, and b = y, finding optimal c, d
    for (int i : special)
        if (i != x && i != y)
            new_special.push_back(i);
    vector<city_distance> other_close_pair = dijkstra(new_special, 1, 2);
    if (!other_close_pair.empty())
        ans = min(ans, close_pair.dist + other_close_pair[0].dist);

    // Let a = x and c = y, finding optimal b, d
    vector<city_distance> x_close, y_close;
    x_close = dijkstra({x}, 2, 1);
    y_close = dijkstra({y}, 2, 1);
    for (int i = 0; i < x_close.size(); ++i)
        for (int j = 0; j < y_close.size(); ++j)
            if (x_close[i].city != y_close[j].city)
                ans = min(ans, x_close[i].dist + y_close[j].dist);

    cout << ans;
    return 0;
}

Compilation message

RelayMarathon.cpp: In function 'std::vector<city_distance> dijkstra(std::vector<int>, int, int)':
RelayMarathon.cpp:28:34: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |         if (vis[cur.city].size() == cnt && is_special[cur.city]) {
      |             ~~~~~~~~~~~~~~~~~~~~~^~~~~~
RelayMarathon.cpp:30:26: warning: comparison of integer expressions of different signedness: 'std::vector<city_distance>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |             if (v.size() == threshold)
      |                 ~~~~~~~~~^~~~~~~~~~~~
RelayMarathon.cpp: In function 'int main()':
RelayMarathon.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<city_distance>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for (int i = 0; i < x_close.size(); ++i)
      |                     ~~^~~~~~~~~~~~~~~~
RelayMarathon.cpp:73:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<city_distance>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for (int j = 0; j < y_close.size(); ++j)
      |                         ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2676 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2680 KB Output is correct
15 Correct 3 ms 2688 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2676 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2772 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 2 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2676 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2680 KB Output is correct
15 Correct 3 ms 2688 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2676 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2772 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 2 ms 2772 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 3 ms 2772 KB Output is correct
34 Correct 2 ms 2644 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 3 ms 2948 KB Output is correct
37 Correct 4 ms 3220 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 21 ms 6452 KB Output is correct
40 Correct 8 ms 3996 KB Output is correct
41 Correct 2 ms 2644 KB Output is correct
42 Correct 10 ms 4012 KB Output is correct
43 Correct 3 ms 2812 KB Output is correct
44 Correct 2 ms 2688 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 40 ms 11056 KB Output is correct
47 Correct 6 ms 3532 KB Output is correct
48 Correct 20 ms 6848 KB Output is correct
49 Correct 27 ms 8520 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 2 ms 2772 KB Output is correct
52 Correct 2 ms 2644 KB Output is correct
53 Correct 13 ms 4624 KB Output is correct
54 Correct 26 ms 6524 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 2 ms 2680 KB Output is correct
58 Correct 31 ms 8852 KB Output is correct
59 Correct 2 ms 2672 KB Output is correct
60 Correct 2 ms 2820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 11296 KB Output is correct
2 Correct 10 ms 7940 KB Output is correct
3 Correct 1635 ms 195140 KB Output is correct
4 Correct 587 ms 73172 KB Output is correct
5 Correct 121 ms 19464 KB Output is correct
6 Correct 70 ms 14248 KB Output is correct
7 Correct 141 ms 22028 KB Output is correct
8 Correct 42 ms 11592 KB Output is correct
9 Correct 56 ms 13604 KB Output is correct
10 Correct 41 ms 12024 KB Output is correct
11 Correct 1543 ms 182020 KB Output is correct
12 Correct 47 ms 12628 KB Output is correct
13 Correct 517 ms 57784 KB Output is correct
14 Correct 100 ms 18056 KB Output is correct
15 Correct 1521 ms 180044 KB Output is correct
16 Correct 37 ms 11896 KB Output is correct
17 Correct 775 ms 93296 KB Output is correct
18 Correct 8 ms 8020 KB Output is correct
19 Correct 1308 ms 128936 KB Output is correct
20 Correct 92 ms 17460 KB Output is correct
21 Correct 77 ms 15192 KB Output is correct
22 Correct 45 ms 11900 KB Output is correct
23 Correct 27 ms 9884 KB Output is correct
24 Correct 1323 ms 158552 KB Output is correct
25 Correct 65 ms 13428 KB Output is correct
26 Correct 50 ms 11492 KB Output is correct
27 Correct 48 ms 12484 KB Output is correct
28 Correct 16 ms 8972 KB Output is correct
29 Correct 95 ms 16144 KB Output is correct
30 Correct 218 ms 27216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2676 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2680 KB Output is correct
15 Correct 3 ms 2688 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2676 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2772 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 2 ms 2772 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 3 ms 2772 KB Output is correct
34 Correct 2 ms 2644 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 3 ms 2948 KB Output is correct
37 Correct 4 ms 3220 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 21 ms 6452 KB Output is correct
40 Correct 8 ms 3996 KB Output is correct
41 Correct 2 ms 2644 KB Output is correct
42 Correct 10 ms 4012 KB Output is correct
43 Correct 3 ms 2812 KB Output is correct
44 Correct 2 ms 2688 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 40 ms 11056 KB Output is correct
47 Correct 6 ms 3532 KB Output is correct
48 Correct 20 ms 6848 KB Output is correct
49 Correct 27 ms 8520 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 2 ms 2772 KB Output is correct
52 Correct 2 ms 2644 KB Output is correct
53 Correct 13 ms 4624 KB Output is correct
54 Correct 26 ms 6524 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 2 ms 2680 KB Output is correct
58 Correct 31 ms 8852 KB Output is correct
59 Correct 2 ms 2672 KB Output is correct
60 Correct 2 ms 2820 KB Output is correct
61 Correct 37 ms 11296 KB Output is correct
62 Correct 10 ms 7940 KB Output is correct
63 Correct 1635 ms 195140 KB Output is correct
64 Correct 587 ms 73172 KB Output is correct
65 Correct 121 ms 19464 KB Output is correct
66 Correct 70 ms 14248 KB Output is correct
67 Correct 141 ms 22028 KB Output is correct
68 Correct 42 ms 11592 KB Output is correct
69 Correct 56 ms 13604 KB Output is correct
70 Correct 41 ms 12024 KB Output is correct
71 Correct 1543 ms 182020 KB Output is correct
72 Correct 47 ms 12628 KB Output is correct
73 Correct 517 ms 57784 KB Output is correct
74 Correct 100 ms 18056 KB Output is correct
75 Correct 1521 ms 180044 KB Output is correct
76 Correct 37 ms 11896 KB Output is correct
77 Correct 775 ms 93296 KB Output is correct
78 Correct 8 ms 8020 KB Output is correct
79 Correct 1308 ms 128936 KB Output is correct
80 Correct 92 ms 17460 KB Output is correct
81 Correct 77 ms 15192 KB Output is correct
82 Correct 45 ms 11900 KB Output is correct
83 Correct 27 ms 9884 KB Output is correct
84 Correct 1323 ms 158552 KB Output is correct
85 Correct 65 ms 13428 KB Output is correct
86 Correct 50 ms 11492 KB Output is correct
87 Correct 48 ms 12484 KB Output is correct
88 Correct 16 ms 8972 KB Output is correct
89 Correct 95 ms 16144 KB Output is correct
90 Correct 218 ms 27216 KB Output is correct
91 Correct 129 ms 15296 KB Output is correct
92 Correct 1951 ms 214260 KB Output is correct
93 Correct 120 ms 17116 KB Output is correct
94 Correct 698 ms 70792 KB Output is correct
95 Correct 10 ms 8020 KB Output is correct
96 Correct 13 ms 8240 KB Output is correct
97 Correct 181 ms 25780 KB Output is correct
98 Correct 66 ms 13452 KB Output is correct
99 Correct 73 ms 13968 KB Output is correct
100 Correct 1579 ms 169940 KB Output is correct
101 Correct 431 ms 48528 KB Output is correct
102 Correct 484 ms 57184 KB Output is correct
103 Correct 1427 ms 161136 KB Output is correct
104 Correct 1039 ms 118596 KB Output is correct
105 Correct 58 ms 12040 KB Output is correct
106 Correct 1203 ms 161464 KB Output is correct
107 Correct 257 ms 33008 KB Output is correct
108 Correct 85 ms 15644 KB Output is correct
109 Correct 19 ms 9428 KB Output is correct
110 Correct 39 ms 11104 KB Output is correct
111 Correct 92 ms 16368 KB Output is correct
112 Correct 1669 ms 198364 KB Output is correct
113 Correct 1730 ms 199880 KB Output is correct
114 Correct 186 ms 19072 KB Output is correct
115 Correct 750 ms 90668 KB Output is correct
116 Correct 1929 ms 210160 KB Output is correct
117 Correct 1318 ms 167740 KB Output is correct
118 Correct 1044 ms 124112 KB Output is correct
119 Correct 1262 ms 144656 KB Output is correct
120 Correct 621 ms 63116 KB Output is correct