제출 #1124443

#제출 시각아이디문제언어결과실행 시간메모리
1124443_8_8_Security Guard (JOI23_guard)C++20
0 / 100
79 ms15292 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = (int)2e5 + 12, b = 18; const ll inf = (ll)1e10; int n, m, q, s[N], sz[N], p[N]; vector<int> g[N]; int get(int v) { if(p[v] == v) return v; return p[v] = get(p[v]); } bool merge(int a, int b) { a = get(a); b = get(b); if(a == b) return 0; p[a] = b; return 1; } void test() { cin >> n >> m >> q; vector<pair<int, int>> vals; for(int i = 1; i <= n; i++) { cin >> s[i]; p[i] = i; vals.push_back({s[i], i}); } for(int i = 0; i < m; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } sort(vals.begin(), vals.end()); for(auto [x, v] : vals) { for(int to : g[v]) { if(merge(v, to)) { sz[v]++; } } } ll res = 0; ll sub = 0; m = n - 1; for(int i = 0; i < n; ) { int j = i, c = 0; while(j < n && vals[j].first == vals[i].first) { c += sz[vals[j].second] - 1; j++; } res += m * 1ll * (vals[i].first - sub); sub += (vals[i].first - sub); m -= c; i = j; } cout << res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while(t--) test(); }
#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...