#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 2;
int n, m, s[MAXN], uf[MAXN], sz[MAXN];
ll sum[MAXN];
vector<int> adj[MAXN], d[MAXN];
vector<pair<int, int> > v;
bool bio[MAXN], ans[MAXN];
int f(int x){
while(uf[x] != -1) x = uf[x];
return x;
}
void join(int u, int v, bool good){
if(u == v) return ;
if(sz[u] > sz[v]) swap(u, v);
uf[u] = v;
sz[v] += sz[u];
sum[v] += sum[u];
if(good){
// if(d[v].size() < d[u].size()) swap(d[u], d[v]);
for(int x : d[u]) d[v].push_back(x);
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; ++i){
cin >> s[i];
v.push_back({s[i], i});
uf[i] = -1; sz[i] = 1;
d[i] = {i};
sum[i] = s[i];
}
for(int i = 0; i < m; ++i){
int u, v;
cin >> u >> v, --u, --v;
adj[u].push_back(v); adj[v].push_back(u);
}
sort(v.begin(), v.end());
for(pair<int, int> p : v){
for(int x : adj[p.second]){
if(bio[x]){
int root = f(x);
join(root, f(p.second), sum[root] >= s[p.second]);
}
}
bio[p.second] = 1;
}
int source = f(v.back().second);
for(int x : d[source]) ans[x] = 1;
for(int i = 0; i < n; ++i) cout << ans[i];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9732 KB |
Output is correct |
4 |
Incorrect |
5 ms |
9864 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
102 ms |
30484 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
162 ms |
32852 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
145 ms |
30748 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9732 KB |
Output is correct |
4 |
Incorrect |
5 ms |
9864 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |