#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;
if (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;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
5136 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
180 ms |
14592 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
246 ms |
14540 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
185 ms |
14568 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
5136 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |