#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 (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;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
5 ms |
5108 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5092 KB |
Output is correct |
9 |
Correct |
379 ms |
5216 KB |
Output is correct |
10 |
Correct |
4 ms |
5076 KB |
Output is correct |
11 |
Correct |
5 ms |
5076 KB |
Output is correct |
12 |
Correct |
4 ms |
5188 KB |
Output is correct |
13 |
Correct |
222 ms |
5076 KB |
Output is correct |
14 |
Correct |
109 ms |
5168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
213 ms |
14792 KB |
Output is correct |
4 |
Execution timed out |
1078 ms |
20196 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
207 ms |
14488 KB |
Output is correct |
3 |
Correct |
213 ms |
18992 KB |
Output is correct |
4 |
Correct |
107 ms |
19032 KB |
Output is correct |
5 |
Execution timed out |
1079 ms |
19108 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
195 ms |
14576 KB |
Output is correct |
3 |
Correct |
207 ms |
19012 KB |
Output is correct |
4 |
Correct |
186 ms |
19044 KB |
Output is correct |
5 |
Correct |
112 ms |
19108 KB |
Output is correct |
6 |
Correct |
116 ms |
18552 KB |
Output is correct |
7 |
Correct |
204 ms |
29744 KB |
Output is correct |
8 |
Execution timed out |
1080 ms |
23360 KB |
Time limit exceeded |
9 |
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 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
5 ms |
5108 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5092 KB |
Output is correct |
9 |
Correct |
379 ms |
5216 KB |
Output is correct |
10 |
Correct |
4 ms |
5076 KB |
Output is correct |
11 |
Correct |
5 ms |
5076 KB |
Output is correct |
12 |
Correct |
4 ms |
5188 KB |
Output is correct |
13 |
Correct |
222 ms |
5076 KB |
Output is correct |
14 |
Correct |
109 ms |
5168 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
213 ms |
14792 KB |
Output is correct |
18 |
Execution timed out |
1078 ms |
20196 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |