#include <bits/stdc++.h>
using namespace std;
#define int long long int
void solve() {
int n, m, po = 0;
cin >> n >> m;
vector<int> s(n+1), ans(n+1), vis(n+1, 0);
vector<pair<int, int>> ch;
vector<vector<int>> adj(n+1);
for (int i = 1; i <= n; i++) {
cin >> s[i];
po += s[i];
ch.push_back({s[i], i});
}
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
sort(ch.begin(), ch.end());
for (int i = 1; i <= n; i++) {
int inh = ch.back().first, ind = ch.back().second;
ch.pop_back();
priority_queue<pair<int, int>> pq;
pq.push({0, ind});
while(!pq.empty()) {
auto [w, a] = pq.top();
pq.pop();
if (vis[a] == i) {
continue;
}
w = abs(w);
if (inh < w) {
break;
}
inh += w;
if (ans[a]) {
ans[ind] = 1;
break;
}
vis[a] = i;
for (int b : adj[a]) {
if (vis[b] == i) {
continue;
}
pq.push({-s[b], b});
}
}
if (po == inh) {
ans[ind] = 1;
}
}
for (int i = 1; i <= n; i++) {
cout << ans[i];
}
cout << endl;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
65 ms |
604 KB |
Output is correct |
5 |
Correct |
12 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
71 ms |
660 KB |
Output is correct |
8 |
Correct |
60 ms |
604 KB |
Output is correct |
9 |
Correct |
222 ms |
704 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
77 ms |
600 KB |
Output is correct |
14 |
Correct |
75 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Execution timed out |
1002 ms |
25460 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
328 ms |
23544 KB |
Output is correct |
3 |
Correct |
330 ms |
23748 KB |
Output is correct |
4 |
Correct |
116 ms |
23732 KB |
Output is correct |
5 |
Execution timed out |
1035 ms |
21960 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1089 ms |
24924 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
65 ms |
604 KB |
Output is correct |
5 |
Correct |
12 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
71 ms |
660 KB |
Output is correct |
8 |
Correct |
60 ms |
604 KB |
Output is correct |
9 |
Correct |
222 ms |
704 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
77 ms |
600 KB |
Output is correct |
14 |
Correct |
75 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
1002 ms |
25460 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |