-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArya's Stunt.cpp
More file actions
executable file
·73 lines (67 loc) · 1.38 KB
/
Arya's Stunt.cpp
File metadata and controls
executable file
·73 lines (67 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
typedef long long ll;
// unhackable custom hash for unordered_map
// Credits : neil
struct custom_hash {
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
x ^= FIXED_RANDOM;
return x ^ (x >> 16);
}
};
//==========================XXXXXXXXXXXXXXXX=============================
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define maxN 10005
vector<int> ar[maxN], ord, sol(maxN);
bool vis[maxN];
int killed, injured, mx;
int dfs(int node) {
int tot = 0;
vis[node] = true;
mx = max(mx, sol[node]);
for (int child : ar[node]) {
if (!vis[child])
tot += dfs(child);
}
tot += sol[node];
return tot;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, m;
cin >> n >> m;
rep(i, 1, n + 1) {
cin >> sol[i];
}
rep(i, 0, m) {
int u, v;
cin >> u >> v;
ar[u].pb(v);
ar[v].pb(u);
}
rep(i, 1, n + 1) {
if (!vis[i]) {
int total = dfs(i);
ord.pb(mx);
killed += sol[mx];
injured += total - sol[mx];
mx = 0;
}
}
sort(all(ord));
cout << killed << " " << injured << "\n";
for (int i : ord)
cout << ord[i] << " ";
cout << "\n";
return 0;
}