#include<bits/stdc++.h>
using namespace std;
mt19937 rnd(51);
#define ll long long
#define pb push_back
#define ld long double
const int N = 2e5 + 10;
vector<int> g[N];
vector<bool> used(N);
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> s(n), good(n), bad(n);
int mx = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
mx = max(mx, s[i]);
}
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].pb(b);
g[b].pb(a);
}
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int i, int j){return s[i] > s[j];});
for (auto i : ord) {
if (s[i] == mx) {
good[i] = 1;
continue;
}
int sum = s[i];
vector<int> arr{i};
set<pair<int,int>> st;
used[i] = 1;
for (auto to : g[i]) {
if (!used[to]) {
used[to] = 1;
arr.pb(to);
st.insert({s[to], to});
}
}
while (st.size() > 0 && st.begin()->first <= sum) {
int v = st.begin()->second;
sum += st.begin()->first;
st.erase(st.begin());
if (bad[v]) {
break;
}
if (good[v] || sum >= mx) {
good[i] = 1;
break;
}
for (auto to : g[v]) {
if (!used[to]) {
used[to] = 1;
arr.pb(to);
st.insert({s[to], to});
}
}
}
if (!good[i]) {
for (auto to : arr) {
bad[to] = 1;
}
}
for (auto to : arr) {
used[to] = 0;
}
}
for (int i = 0; i < n; i++) {
cout << good[i];
}
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
200 ms |
14620 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
220 ms |
14516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
204 ms |
14580 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |