#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int n, m, val[200002], ind[200002], p[200002], ok[200002], sz[200002];
vector<int>G2[200002];
vector<int>G[200002];
int find (int x) {
if (p[x] == x)
return x;
return p[x] = find(p[x]);
}
void Union (int a, int b) {
a = find(a);
b = find(b);
if (a != b) {
G[a].push_back(b);
p[b] = a;
}
}
bool cmp (int a, int b) {
if (val[a] == val[b])
return a < b;
return val[a] < val[b];
}
void dfs (int nod, int par) {
assert(nod > 1 && val[nod] <= val[par]);
sz[nod] = val[nod];
for (auto it : G[nod]) {
if (it == par)
continue;
dfs(it, nod);
sz[nod] += sz[it];
}
ok[nod] = (sz[nod] >= val[par]);
}
void dfs2 (int nod, int par, bool idk) {
for (auto it : G[nod]) {
if (it == par)
continue;
dfs2(it, nod, (idk & ok[it]));
}
ok[nod] = idk;
}
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> val[i];
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
G2[x].push_back(y);
G2[y].push_back(x);
}
for (int i = 1; i <= n; i++)
ind[i] = p[i] = i;
sort(ind + 1, ind + n + 1, cmp);
for (int i = 1; i <= n; i++)
for (auto it : G2[ind[i]])
if (make_pair(val[it], it) <= make_pair(val[ind[i]], ind[i]))
Union(ind[i], it);
dfs(find(1), 0);
dfs2(find(1), 0, 1);
for (int i = 1; i <= n; i++)
cout << ok[i];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
19540 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
19540 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
19540 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
19540 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
19540 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |