Submission #1064859

#TimeUsernameProblemLanguageResultExecution timeMemory
1064859GusterGoose27Security Guard (JOI23_guard)C++17
100 / 100
144 ms16212 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5+5; int n, m, q; typedef long long ll; typedef array<int, 2> ar2; int uf[MAXN]; int val[MAXN]; ar2 edges[2*MAXN]; const int inf = 1e9; int find(int i) { return uf[i] == i ? i : uf[i] = find(uf[i]); } int wt(ar2 i) { return val[i[0]] + val[i[1]]; } struct cmp { bool operator()(ar2 i, ar2 j) { return ar2({wt(i), i[0]}) < ar2({wt(j), j[0]}); } } cmp; int merge(int a, int b) { if (val[a] > val[b]) swap(a, b); uf[b] = a; return val[b]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> q; // assert(q == 0); iota(uf, uf+n, 0); ll s = 0; int mx = 0, mn = inf; for (int i = 0; i < n; i++) { cin >> val[i]; s -= val[i]; mx = max(val[i], mx); mn = min(val[i], mn); } s += mx; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; edges[i] = {a-1, b-1}; } sort(edges, edges+m, cmp); vector<int> savings; for (int i = 0; i < m; i++) { int a = find(edges[i][0]); int b = find(edges[i][1]); int v = wt(edges[i]); if (a != b) { savings.push_back(v-merge(a, b)-mn); s += v; } } sort(savings.rbegin(), savings.rend()); cout << s << '\n'; for (int v = 0; v < q; v++) { s -= (v >= savings.size() ? 0 : savings[v]); cout << s << '\n'; } }

Compilation message (stderr)

guard.cpp: In function 'int main()':
guard.cpp:68:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   s -= (v >= savings.size() ? 0 : savings[v]);
      |         ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...