답안 #970809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970809 2024-04-27T10:22:20 Z thinknoexit Security Guard (JOI23_guard) C++17
100 / 100
175 ms 30972 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 200200;
int a[N], p[N];
struct Edge {
    int u, v;
    ll w;
    bool operator < (const Edge& o) const {
        return w > o.w;
    }
};
vector<Edge> e;
priority_queue<Edge> pq;
int fr(int i) {
    return p[i] == i ? i : p[i] = fr(p[i]);
}
ll res[N], cost[N];
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 1;i <= n;i++) cin >> a[i];
    int mn = *min_element(a + 1, a + 1 + n);
    int mx = *max_element(a + 1, a + 1 + n);
    res[n - 1] = mx + 1ll * (n - 2) * mn;
    for (int i = 1;i <= n;i++) p[i] = i;
    while (m--) {
        int u, v;
        cin >> u >> v;
        e.push_back({ u, v, a[u] + a[v] });
    }
    int idx = 0;
    sort(e.rbegin(), e.rend());
    for (auto& x : e) {
        int u = x.u, v = x.v;
        int pu = fr(u), pv = fr(v);
        if (pu == pv) continue;
        p[pu] = pv;
        if (a[u] < a[v]) swap(u, v);
        pq.push({ u, v, a[v] - mn });
    }
    for (int i = 1;i <= n;i++) p[i] = i, cost[i] = a[i] + mn;
    int now = n - 2;
    while (now >= 0) {
        auto x = pq.top();
        pq.pop();
        int u = x.u, v = x.v;
        if (fr(u) == fr(v)) continue;
        ll w = x.w;
        ll w2 = a[u] + a[v] - max(cost[fr(u)], cost[fr(v)]);
        if (w != w2) {
            pq.push({ u, v, w2 });
            continue;
        }
        if (cost[fr(u)] < cost[fr(v)]) swap(u, v);
        p[fr(u)] = fr(v);
        res[now] = res[now + 1] + w;
        now--;
    }
    for (int i = 0;i <= q;i++) {
        cout << res[min(i, n - 1)] << '\n';
    }
    return 0;
}
/*
2 3
1 2
3 6
8 9
6 9
9 10
1 4
7 8
2 5
*/

Compilation message

guard.cpp: In function 'int main()':
guard.cpp:33:9: warning: unused variable 'idx' [-Wunused-variable]
   33 |     int idx = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 60 ms 16840 KB Output is correct
3 Correct 57 ms 16072 KB Output is correct
4 Correct 61 ms 16068 KB Output is correct
5 Correct 69 ms 15048 KB Output is correct
6 Correct 62 ms 17336 KB Output is correct
7 Correct 60 ms 17608 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 60 ms 16840 KB Output is correct
3 Correct 57 ms 16072 KB Output is correct
4 Correct 61 ms 16068 KB Output is correct
5 Correct 69 ms 15048 KB Output is correct
6 Correct 62 ms 17336 KB Output is correct
7 Correct 60 ms 17608 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 103 ms 19284 KB Output is correct
11 Correct 70 ms 18836 KB Output is correct
12 Correct 66 ms 19144 KB Output is correct
13 Correct 63 ms 18884 KB Output is correct
14 Correct 99 ms 17056 KB Output is correct
15 Correct 101 ms 18444 KB Output is correct
16 Correct 100 ms 16572 KB Output is correct
17 Correct 105 ms 17084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 60 ms 16840 KB Output is correct
3 Correct 57 ms 16072 KB Output is correct
4 Correct 61 ms 16068 KB Output is correct
5 Correct 69 ms 15048 KB Output is correct
6 Correct 62 ms 17336 KB Output is correct
7 Correct 60 ms 17608 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 103 ms 19284 KB Output is correct
11 Correct 70 ms 18836 KB Output is correct
12 Correct 66 ms 19144 KB Output is correct
13 Correct 63 ms 18884 KB Output is correct
14 Correct 99 ms 17056 KB Output is correct
15 Correct 101 ms 18444 KB Output is correct
16 Correct 100 ms 16572 KB Output is correct
17 Correct 105 ms 17084 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 113 ms 18484 KB Output is correct
20 Correct 109 ms 19140 KB Output is correct
21 Correct 107 ms 17580 KB Output is correct
22 Correct 112 ms 17344 KB Output is correct
23 Correct 102 ms 18368 KB Output is correct
24 Correct 92 ms 17348 KB Output is correct
25 Correct 88 ms 17088 KB Output is correct
26 Correct 90 ms 18112 KB Output is correct
27 Correct 92 ms 18112 KB Output is correct
28 Correct 103 ms 16580 KB Output is correct
29 Correct 103 ms 17128 KB Output is correct
30 Correct 101 ms 17344 KB Output is correct
31 Correct 93 ms 18072 KB Output is correct
32 Correct 105 ms 19140 KB Output is correct
33 Correct 79 ms 16340 KB Output is correct
34 Correct 85 ms 17800 KB Output is correct
35 Correct 92 ms 17856 KB Output is correct
36 Correct 73 ms 18628 KB Output is correct
37 Correct 73 ms 17576 KB Output is correct
38 Correct 84 ms 18140 KB Output is correct
39 Correct 74 ms 17960 KB Output is correct
40 Correct 82 ms 18364 KB Output is correct
41 Correct 79 ms 16832 KB Output is correct
42 Correct 77 ms 17088 KB Output is correct
43 Correct 87 ms 16584 KB Output is correct
44 Correct 105 ms 18212 KB Output is correct
45 Correct 85 ms 17168 KB Output is correct
46 Correct 88 ms 17456 KB Output is correct
47 Correct 102 ms 19496 KB Output is correct
48 Correct 102 ms 17088 KB Output is correct
49 Correct 83 ms 18112 KB Output is correct
50 Correct 108 ms 18116 KB Output is correct
51 Correct 79 ms 18372 KB Output is correct
52 Correct 73 ms 15204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 60 ms 16840 KB Output is correct
3 Correct 57 ms 16072 KB Output is correct
4 Correct 61 ms 16068 KB Output is correct
5 Correct 69 ms 15048 KB Output is correct
6 Correct 62 ms 17336 KB Output is correct
7 Correct 60 ms 17608 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 103 ms 19284 KB Output is correct
11 Correct 70 ms 18836 KB Output is correct
12 Correct 66 ms 19144 KB Output is correct
13 Correct 63 ms 18884 KB Output is correct
14 Correct 99 ms 17056 KB Output is correct
15 Correct 101 ms 18444 KB Output is correct
16 Correct 100 ms 16572 KB Output is correct
17 Correct 105 ms 17084 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 113 ms 18484 KB Output is correct
20 Correct 109 ms 19140 KB Output is correct
21 Correct 107 ms 17580 KB Output is correct
22 Correct 112 ms 17344 KB Output is correct
23 Correct 102 ms 18368 KB Output is correct
24 Correct 92 ms 17348 KB Output is correct
25 Correct 88 ms 17088 KB Output is correct
26 Correct 90 ms 18112 KB Output is correct
27 Correct 92 ms 18112 KB Output is correct
28 Correct 103 ms 16580 KB Output is correct
29 Correct 103 ms 17128 KB Output is correct
30 Correct 101 ms 17344 KB Output is correct
31 Correct 93 ms 18072 KB Output is correct
32 Correct 105 ms 19140 KB Output is correct
33 Correct 79 ms 16340 KB Output is correct
34 Correct 85 ms 17800 KB Output is correct
35 Correct 92 ms 17856 KB Output is correct
36 Correct 73 ms 18628 KB Output is correct
37 Correct 73 ms 17576 KB Output is correct
38 Correct 84 ms 18140 KB Output is correct
39 Correct 74 ms 17960 KB Output is correct
40 Correct 82 ms 18364 KB Output is correct
41 Correct 79 ms 16832 KB Output is correct
42 Correct 77 ms 17088 KB Output is correct
43 Correct 87 ms 16584 KB Output is correct
44 Correct 105 ms 18212 KB Output is correct
45 Correct 85 ms 17168 KB Output is correct
46 Correct 88 ms 17456 KB Output is correct
47 Correct 102 ms 19496 KB Output is correct
48 Correct 102 ms 17088 KB Output is correct
49 Correct 83 ms 18112 KB Output is correct
50 Correct 108 ms 18116 KB Output is correct
51 Correct 79 ms 18372 KB Output is correct
52 Correct 73 ms 15204 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 112 ms 17956 KB Output is correct
55 Correct 112 ms 17340 KB Output is correct
56 Correct 125 ms 23484 KB Output is correct
57 Correct 162 ms 26680 KB Output is correct
58 Correct 152 ms 27316 KB Output is correct
59 Correct 150 ms 25780 KB Output is correct
60 Correct 119 ms 23072 KB Output is correct
61 Correct 142 ms 26040 KB Output is correct
62 Correct 146 ms 26036 KB Output is correct
63 Correct 115 ms 19132 KB Output is correct
64 Correct 123 ms 23260 KB Output is correct
65 Correct 138 ms 26552 KB Output is correct
66 Correct 141 ms 26040 KB Output is correct
67 Correct 156 ms 25744 KB Output is correct
68 Correct 91 ms 16580 KB Output is correct
69 Correct 114 ms 26032 KB Output is correct
70 Correct 88 ms 18112 KB Output is correct
71 Correct 77 ms 17064 KB Output is correct
72 Correct 76 ms 17328 KB Output is correct
73 Correct 86 ms 16972 KB Output is correct
74 Correct 74 ms 19136 KB Output is correct
75 Correct 79 ms 17684 KB Output is correct
76 Correct 77 ms 16612 KB Output is correct
77 Correct 81 ms 17088 KB Output is correct
78 Correct 90 ms 17512 KB Output is correct
79 Correct 153 ms 26008 KB Output is correct
80 Correct 99 ms 19620 KB Output is correct
81 Correct 117 ms 26812 KB Output is correct
82 Correct 132 ms 27552 KB Output is correct
83 Correct 141 ms 26792 KB Output is correct
84 Correct 138 ms 26244 KB Output is correct
85 Correct 107 ms 19396 KB Output is correct
86 Correct 77 ms 17208 KB Output is correct
87 Correct 70 ms 17096 KB Output is correct
88 Correct 162 ms 26624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 13 ms 6748 KB Output is correct
9 Correct 13 ms 6644 KB Output is correct
10 Correct 13 ms 6492 KB Output is correct
11 Correct 13 ms 6748 KB Output is correct
12 Correct 13 ms 6744 KB Output is correct
13 Correct 14 ms 6748 KB Output is correct
14 Correct 14 ms 6536 KB Output is correct
15 Correct 13 ms 6744 KB Output is correct
16 Correct 14 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 13 ms 6748 KB Output is correct
9 Correct 13 ms 6644 KB Output is correct
10 Correct 13 ms 6492 KB Output is correct
11 Correct 13 ms 6748 KB Output is correct
12 Correct 13 ms 6744 KB Output is correct
13 Correct 14 ms 6748 KB Output is correct
14 Correct 14 ms 6536 KB Output is correct
15 Correct 13 ms 6744 KB Output is correct
16 Correct 14 ms 6744 KB Output is correct
17 Correct 19 ms 7376 KB Output is correct
18 Correct 19 ms 7580 KB Output is correct
19 Correct 30 ms 8916 KB Output is correct
20 Correct 47 ms 11200 KB Output is correct
21 Correct 53 ms 12480 KB Output is correct
22 Correct 46 ms 11196 KB Output is correct
23 Correct 88 ms 18360 KB Output is correct
24 Correct 58 ms 12736 KB Output is correct
25 Correct 16 ms 7000 KB Output is correct
26 Correct 32 ms 9932 KB Output is correct
27 Correct 17 ms 7644 KB Output is correct
28 Correct 14 ms 7000 KB Output is correct
29 Correct 13 ms 7000 KB Output is correct
30 Correct 14 ms 7000 KB Output is correct
31 Correct 12 ms 5724 KB Output is correct
32 Correct 12 ms 5724 KB Output is correct
33 Correct 14 ms 6944 KB Output is correct
34 Correct 15 ms 7136 KB Output is correct
35 Correct 32 ms 9272 KB Output is correct
36 Correct 91 ms 17080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 60 ms 16840 KB Output is correct
3 Correct 57 ms 16072 KB Output is correct
4 Correct 61 ms 16068 KB Output is correct
5 Correct 69 ms 15048 KB Output is correct
6 Correct 62 ms 17336 KB Output is correct
7 Correct 60 ms 17608 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 103 ms 19284 KB Output is correct
11 Correct 70 ms 18836 KB Output is correct
12 Correct 66 ms 19144 KB Output is correct
13 Correct 63 ms 18884 KB Output is correct
14 Correct 99 ms 17056 KB Output is correct
15 Correct 101 ms 18444 KB Output is correct
16 Correct 100 ms 16572 KB Output is correct
17 Correct 105 ms 17084 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 113 ms 18484 KB Output is correct
20 Correct 109 ms 19140 KB Output is correct
21 Correct 107 ms 17580 KB Output is correct
22 Correct 112 ms 17344 KB Output is correct
23 Correct 102 ms 18368 KB Output is correct
24 Correct 92 ms 17348 KB Output is correct
25 Correct 88 ms 17088 KB Output is correct
26 Correct 90 ms 18112 KB Output is correct
27 Correct 92 ms 18112 KB Output is correct
28 Correct 103 ms 16580 KB Output is correct
29 Correct 103 ms 17128 KB Output is correct
30 Correct 101 ms 17344 KB Output is correct
31 Correct 93 ms 18072 KB Output is correct
32 Correct 105 ms 19140 KB Output is correct
33 Correct 79 ms 16340 KB Output is correct
34 Correct 85 ms 17800 KB Output is correct
35 Correct 92 ms 17856 KB Output is correct
36 Correct 73 ms 18628 KB Output is correct
37 Correct 73 ms 17576 KB Output is correct
38 Correct 84 ms 18140 KB Output is correct
39 Correct 74 ms 17960 KB Output is correct
40 Correct 82 ms 18364 KB Output is correct
41 Correct 79 ms 16832 KB Output is correct
42 Correct 77 ms 17088 KB Output is correct
43 Correct 87 ms 16584 KB Output is correct
44 Correct 105 ms 18212 KB Output is correct
45 Correct 85 ms 17168 KB Output is correct
46 Correct 88 ms 17456 KB Output is correct
47 Correct 102 ms 19496 KB Output is correct
48 Correct 102 ms 17088 KB Output is correct
49 Correct 83 ms 18112 KB Output is correct
50 Correct 108 ms 18116 KB Output is correct
51 Correct 79 ms 18372 KB Output is correct
52 Correct 73 ms 15204 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 112 ms 17956 KB Output is correct
55 Correct 112 ms 17340 KB Output is correct
56 Correct 125 ms 23484 KB Output is correct
57 Correct 162 ms 26680 KB Output is correct
58 Correct 152 ms 27316 KB Output is correct
59 Correct 150 ms 25780 KB Output is correct
60 Correct 119 ms 23072 KB Output is correct
61 Correct 142 ms 26040 KB Output is correct
62 Correct 146 ms 26036 KB Output is correct
63 Correct 115 ms 19132 KB Output is correct
64 Correct 123 ms 23260 KB Output is correct
65 Correct 138 ms 26552 KB Output is correct
66 Correct 141 ms 26040 KB Output is correct
67 Correct 156 ms 25744 KB Output is correct
68 Correct 91 ms 16580 KB Output is correct
69 Correct 114 ms 26032 KB Output is correct
70 Correct 88 ms 18112 KB Output is correct
71 Correct 77 ms 17064 KB Output is correct
72 Correct 76 ms 17328 KB Output is correct
73 Correct 86 ms 16972 KB Output is correct
74 Correct 74 ms 19136 KB Output is correct
75 Correct 79 ms 17684 KB Output is correct
76 Correct 77 ms 16612 KB Output is correct
77 Correct 81 ms 17088 KB Output is correct
78 Correct 90 ms 17512 KB Output is correct
79 Correct 153 ms 26008 KB Output is correct
80 Correct 99 ms 19620 KB Output is correct
81 Correct 117 ms 26812 KB Output is correct
82 Correct 132 ms 27552 KB Output is correct
83 Correct 141 ms 26792 KB Output is correct
84 Correct 138 ms 26244 KB Output is correct
85 Correct 107 ms 19396 KB Output is correct
86 Correct 77 ms 17208 KB Output is correct
87 Correct 70 ms 17096 KB Output is correct
88 Correct 162 ms 26624 KB Output is correct
89 Correct 1 ms 4444 KB Output is correct
90 Correct 1 ms 4700 KB Output is correct
91 Correct 1 ms 4444 KB Output is correct
92 Correct 1 ms 4444 KB Output is correct
93 Correct 1 ms 4440 KB Output is correct
94 Correct 1 ms 4444 KB Output is correct
95 Correct 1 ms 4444 KB Output is correct
96 Correct 13 ms 6748 KB Output is correct
97 Correct 13 ms 6644 KB Output is correct
98 Correct 13 ms 6492 KB Output is correct
99 Correct 13 ms 6748 KB Output is correct
100 Correct 13 ms 6744 KB Output is correct
101 Correct 14 ms 6748 KB Output is correct
102 Correct 14 ms 6536 KB Output is correct
103 Correct 13 ms 6744 KB Output is correct
104 Correct 14 ms 6744 KB Output is correct
105 Correct 19 ms 7376 KB Output is correct
106 Correct 19 ms 7580 KB Output is correct
107 Correct 30 ms 8916 KB Output is correct
108 Correct 47 ms 11200 KB Output is correct
109 Correct 53 ms 12480 KB Output is correct
110 Correct 46 ms 11196 KB Output is correct
111 Correct 88 ms 18360 KB Output is correct
112 Correct 58 ms 12736 KB Output is correct
113 Correct 16 ms 7000 KB Output is correct
114 Correct 32 ms 9932 KB Output is correct
115 Correct 17 ms 7644 KB Output is correct
116 Correct 14 ms 7000 KB Output is correct
117 Correct 13 ms 7000 KB Output is correct
118 Correct 14 ms 7000 KB Output is correct
119 Correct 12 ms 5724 KB Output is correct
120 Correct 12 ms 5724 KB Output is correct
121 Correct 14 ms 6944 KB Output is correct
122 Correct 15 ms 7136 KB Output is correct
123 Correct 32 ms 9272 KB Output is correct
124 Correct 91 ms 17080 KB Output is correct
125 Correct 125 ms 19256 KB Output is correct
126 Correct 125 ms 19000 KB Output is correct
127 Correct 134 ms 21388 KB Output is correct
128 Correct 175 ms 30972 KB Output is correct
129 Correct 151 ms 29108 KB Output is correct
130 Correct 160 ms 29832 KB Output is correct
131 Correct 163 ms 29952 KB Output is correct
132 Correct 158 ms 30180 KB Output is correct
133 Correct 148 ms 29624 KB Output is correct
134 Correct 124 ms 19512 KB Output is correct
135 Correct 129 ms 20552 KB Output is correct
136 Correct 158 ms 29604 KB Output is correct
137 Correct 157 ms 30388 KB Output is correct
138 Correct 164 ms 30520 KB Output is correct
139 Correct 98 ms 17248 KB Output is correct
140 Correct 125 ms 27572 KB Output is correct
141 Correct 109 ms 20468 KB Output is correct
142 Correct 104 ms 20196 KB Output is correct
143 Correct 87 ms 19772 KB Output is correct
144 Correct 97 ms 21292 KB Output is correct
145 Correct 86 ms 19260 KB Output is correct
146 Correct 93 ms 18748 KB Output is correct
147 Correct 90 ms 17472 KB Output is correct
148 Correct 88 ms 19300 KB Output is correct
149 Correct 96 ms 20372 KB Output is correct
150 Correct 167 ms 29364 KB Output is correct
151 Correct 111 ms 21176 KB Output is correct
152 Correct 139 ms 28808 KB Output is correct
153 Correct 142 ms 30552 KB Output is correct
154 Correct 156 ms 30132 KB Output is correct
155 Correct 148 ms 28604 KB Output is correct
156 Correct 122 ms 20380 KB Output is correct
157 Correct 96 ms 20832 KB Output is correct
158 Correct 81 ms 17700 KB Output is correct
159 Correct 174 ms 28856 KB Output is correct