#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 2e5 + 25;
vector <int> adj2[MAXN];
vector <int> adj[MAXN];
bool ok[MAXN];
set <int> pp;
int cnt[MAXN];
bool vis[MAXN];
int sum = 0;
vector <int> cur;
int y;
void dfs (int pos) {
vis[pos] = 1; sum += cnt[pos]; cur.push_back(pos);
for (auto j : adj[pos]) if (!vis[j] && cnt[j] <= y) dfs(j);
}
signed main () {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> cnt[i];
pp.insert(cnt[i]);
}
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
adj2[a].push_back(b);
adj2[b].push_back(a);
}
for (int i = 1; i <= n; i++) ok[i] = 1;
int z = pp.size();
for (int l = 0; l + 1 < z; l++) {
auto i = *(pp.begin()); pp.erase(i); y = i;
if (pp.empty()) break;
for (int j = 1; j <= n; j++) {
for (auto k : adj2[j]) {
if (cnt[j] == i || cnt[k] == i) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
memset(vis, 0, sizeof(vis));
for (int j = 1; j <= n; j++) {
if (!vis[j] && cnt[j] <= y) {
sum = 0; cur.clear();
dfs(j);
if (sum < *(pp.begin())) {
for (auto l : cur) {
ok[l] = 0;
}
}
}
}
}
for (int i = 1; i <= n; i++) cout << ok[i];
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
2 ms |
11612 KB |
Output is correct |
3 |
Correct |
2 ms |
11612 KB |
Output is correct |
4 |
Runtime error |
14 ms |
23644 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
11608 KB |
Output is correct |
2 |
Correct |
2 ms |
11612 KB |
Output is correct |
3 |
Runtime error |
360 ms |
57436 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
11612 KB |
Output is correct |
2 |
Runtime error |
298 ms |
55120 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
11608 KB |
Output is correct |
2 |
Runtime error |
227 ms |
37860 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
2 ms |
11612 KB |
Output is correct |
3 |
Correct |
2 ms |
11612 KB |
Output is correct |
4 |
Runtime error |
14 ms |
23644 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |