#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 (bad[i]) continue;
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 |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
5 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5056 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5204 KB |
Output is correct |
10 |
Correct |
4 ms |
5076 KB |
Output is correct |
11 |
Correct |
4 ms |
5076 KB |
Output is correct |
12 |
Correct |
4 ms |
5084 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
10 ms |
5184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
5076 KB |
Output is correct |
3 |
Correct |
260 ms |
14560 KB |
Output is correct |
4 |
Correct |
155 ms |
16952 KB |
Output is correct |
5 |
Correct |
167 ms |
18576 KB |
Output is correct |
6 |
Correct |
178 ms |
18960 KB |
Output is correct |
7 |
Correct |
199 ms |
19008 KB |
Output is correct |
8 |
Correct |
177 ms |
19032 KB |
Output is correct |
9 |
Correct |
155 ms |
19028 KB |
Output is correct |
10 |
Correct |
134 ms |
18940 KB |
Output is correct |
11 |
Correct |
89 ms |
18764 KB |
Output is correct |
12 |
Correct |
160 ms |
17660 KB |
Output is correct |
13 |
Correct |
119 ms |
18528 KB |
Output is correct |
14 |
Correct |
120 ms |
18652 KB |
Output is correct |
15 |
Correct |
244 ms |
19024 KB |
Output is correct |
16 |
Execution timed out |
1081 ms |
18120 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
201 ms |
14680 KB |
Output is correct |
3 |
Correct |
218 ms |
14696 KB |
Output is correct |
4 |
Correct |
112 ms |
14824 KB |
Output is correct |
5 |
Correct |
141 ms |
15640 KB |
Output is correct |
6 |
Correct |
238 ms |
19132 KB |
Output is correct |
7 |
Correct |
186 ms |
19124 KB |
Output is correct |
8 |
Correct |
166 ms |
19112 KB |
Output is correct |
9 |
Execution timed out |
1076 ms |
18112 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
201 ms |
14588 KB |
Output is correct |
3 |
Correct |
233 ms |
14760 KB |
Output is correct |
4 |
Correct |
181 ms |
14764 KB |
Output is correct |
5 |
Correct |
109 ms |
14796 KB |
Output is correct |
6 |
Correct |
112 ms |
14352 KB |
Output is correct |
7 |
Correct |
220 ms |
25540 KB |
Output is correct |
8 |
Execution timed out |
1050 ms |
20108 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
5 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5076 KB |
Output is correct |
6 |
Correct |
3 ms |
5056 KB |
Output is correct |
7 |
Correct |
4 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5204 KB |
Output is correct |
10 |
Correct |
4 ms |
5076 KB |
Output is correct |
11 |
Correct |
4 ms |
5076 KB |
Output is correct |
12 |
Correct |
4 ms |
5084 KB |
Output is correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Correct |
10 ms |
5184 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
5076 KB |
Output is correct |
17 |
Correct |
260 ms |
14560 KB |
Output is correct |
18 |
Correct |
155 ms |
16952 KB |
Output is correct |
19 |
Correct |
167 ms |
18576 KB |
Output is correct |
20 |
Correct |
178 ms |
18960 KB |
Output is correct |
21 |
Correct |
199 ms |
19008 KB |
Output is correct |
22 |
Correct |
177 ms |
19032 KB |
Output is correct |
23 |
Correct |
155 ms |
19028 KB |
Output is correct |
24 |
Correct |
134 ms |
18940 KB |
Output is correct |
25 |
Correct |
89 ms |
18764 KB |
Output is correct |
26 |
Correct |
160 ms |
17660 KB |
Output is correct |
27 |
Correct |
119 ms |
18528 KB |
Output is correct |
28 |
Correct |
120 ms |
18652 KB |
Output is correct |
29 |
Correct |
244 ms |
19024 KB |
Output is correct |
30 |
Execution timed out |
1081 ms |
18120 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |