#include "bits/stdc++.h"
using namespace std;
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
using ll = long long;
int s[200005];
int par[200005];
int sz[200005];
vector<int> tracker[200005];
bool able[200005];
int findset(int i) {
return (par[i] == i ? i : par[i] = findset(par[i]));
}
void merge(int a, int b) {
if (a == b) return;
if (tracker[a].size() > tracker[b].size()) swap(a, b);
for (auto cur : tracker[a]) tracker[b].push_back(cur);
par[a] = b;
sz[b] += sz[a];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> s[i];
for (int i = 1; i <= n; i++) {
par[i] = i;
sz[i] = s[i];
tracker[i].push_back(i);
}
vector<pair<int, int>> edges;
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
if (s[a] < s[b]) edges.emplace_back(a, b);
else edges.emplace_back(b, a);
}
sort(edges.begin(), edges.end(), [](pair<int, int> a, pair<int, int> b) {
if (s[a.first] == s[b.first]) {
return s[a.second] < s[b.second];
}
return s[a.first] < s[b.first];
});
for (int i = 1; i <= n; i++) able[i] =true;
for (auto edge : edges) {
int a = findset(edge.first), b = findset(edge.second);
// check if edge.first -> edge.second
// if (a == b) continue;
if (sz[a] >= s[edge.second]) {
// still ok
merge(a, b);
} else {
for (auto cur : tracker[a]) {
able[cur] = false;
}
tracker[a].clear(); tracker[a].shrink_to_fit();
merge(a, b);
}
}
for (int i = 1; i <= n; i++) {
if (able[i]) cout << "1";
else cout << "0";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
3 ms |
5172 KB |
Output isn't correct |
5 |
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 |
Incorrect |
100 ms |
16760 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
131 ms |
16696 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
130 ms |
16768 KB |
Output isn't correct |
3 |
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 |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
3 ms |
5172 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |