#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 200500;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n;
int s[N];
bool can[N];
struct dsu{
vector<int> p;
vector<long long> sum;
dsu(){
p.resize(n);
iota(all(p), 0);
sum.resize(n);
for (int i = 0; i < n; i++) sum[i] = s[i];
}
int leader(int x){
return (x == p[x] ? x : p[x] = leader(p[x]));
}
bool unite(int x, int y){
int px = leader(x);
int py = leader(y);
if (px == py) return false;
if (sum[px] < s[y]){
for (int i = 0; i < n; i++){
if (leader(i) == px) can[i] = false;
}
}
if (sum[py] < s[x]){
for (int i = 0; i < n; i++){
if (leader(i) == py) can[i] = false;
}
}
sum[y] += sum[x];
p[x] = y;
return true;
}
};
vector<int> g[N];
void solve(){
int m;
cin >> n >> m;
for (int i = 0; i < n; i++){
cin >> s[i];
}
while (m--){
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> perm(n);
iota(all(perm), 0);
sort(all(perm), [](int i, int j){
return s[i] < s[j];
});
fill(can, can + n, true);
dsu d;
for (int i : perm){
sort(all(g[i]), [](int x, int y){
return s[x] < s[y];
});
for (int j : g[i]){
d.unite(i, j);
}
}
for (int i = 0; i < n; i++){
cout << can[i];
}
}
int main() {
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
9 ms |
5076 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
5012 KB |
Output is correct |
3 |
Execution timed out |
1085 ms |
15324 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Execution timed out |
1086 ms |
15224 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Execution timed out |
1067 ms |
15308 KB |
Time limit exceeded |
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 |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
9 ms |
5076 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |