#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> nums;
vector<bool> ans;
vector<pair<int, pair<int, int>>> pairs;
struct dsu {
vector<ll> par, siz;
dsu(int n) {
par.resize(n);
siz.resize(n);
for(int i = 0; i < n; i++) {
par[i] = i;
siz[i] = nums[i];
}
}
int get(int x) {
if(x == par[x]) return x;
return par[x] = get(par[x]);
}
int getsiz(int x) {
return siz[get(x)];
}
bool unite(int x, int y) {
x = get(x); y = get(y);
if(x == y) return false;
par[x] = y;
siz[y] += siz[x];
return true;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
nums.resize(n);
ans.resize(n, 1);
pairs.resize(m);
for(int i = 0; i < n; i++) {
cin >> nums[i];
}
dsu uf(n);
for(int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--; y--;
pairs.push_back({max(nums[x], nums[y]), {x, y}});
}
sort(pairs.begin(), pairs.end());
for(auto p : pairs) {
int x, y;
tie(x, y) = p.second;
if(uf.getsiz(x) < nums[y]) ans[x] = 0;
if(uf.getsiz(y) < nums[x]) ans[y] = 0;
uf.unite(x, y);
}
for(int i = 0; i < n; i++) {
cout << ans[i];
}
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
244 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
117 ms |
9072 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
99 ms |
9072 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
110 ms |
9132 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |