#include <bits/stdc++.h>
using namespace std;
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int N = 2e5+10, MOD = 1e9+7;
// keep removing the max node, mark component as bad if it's sum is < value of the node
int n, m;
int s[N], par[N];
ll sum[N];
vector<int> st[N], good[N], adj[N];
bool ans[N];
void mark_bad(int c) {
c = par[c];
for (int x : good[c]) ans[x] = 0;
good[c].clear();
}
void union_sets(int a, int b) {
a = par[a], b = par[b];
if (a == b) return;
if (sz(st[a]) < sz(st[b])) swap(a, b);
for (int x : st[b]) {
st[a].push_back(x);
}
st[b].clear();
for (int x : good[b]) {
good[a].push_back(x);
}
good[b].clear();
sum[a] += sum[b], sum[b] = 0;
}
void solve() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b, --a, --b;
adj[a].push_back(b), adj[b].push_back(a);
}
for (int i = 0; i < n; i++) {
par[i] = i; sum[i] = s[i];
st[i].push_back(i);
good[i].push_back(i);
}
vector<int> ord(n); iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int x, int y) { return s[x] < s[y]; });
fill(ans, ans + n, 1);
vector<bool> hit(n);
for (int x : ord) {
for (int nxt : adj[x]) {
int v = par[nxt];
if (sum[v] < s[x]) {
mark_bad(v);
}
}
for (int nxt : adj[x]) if (hit[nxt]) {
union_sets(x, nxt);
}
hit[x] = 1;
}
for (int i = 0; i < n; i++) cout << ans[i];
cout << '\n';
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int T = 1;
// cin >> T;
while (T--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14440 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Incorrect |
9 ms |
14584 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Incorrect |
163 ms |
42352 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Incorrect |
257 ms |
41744 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Incorrect |
246 ms |
42180 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14440 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Incorrect |
9 ms |
14584 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |