#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define lb lower_bound
#define int ll
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int N, M, S[200001], par[200001];
vector<int> adj[200001], sub[200001], D[200001];
int res[200001]; bool vis[200001], processed[200001];
int findSet(int v) {
if(par[v] == v) return v;
return par[v] = findSet(par[v]);
}
void unionSet(int u, int v) {
u = findSet(u), v = findSet(v);
if(u == v) return;
par[v] = u; S[u] += S[v];
}
void dfs(int v, bool state) {
res[v] &= state;
for(auto u : D[v]) {
dfs(u, res[v]);
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> M; vector<ii> E;
for(int l = 1; l <= N; l++) {
cin >> S[l]; E.pb({S[l], l});
par[l] = l; sub[l].pb(l); res[l] = 1;
}
sort(E.begin(), E.end());
for(int l = 0; l < M; l++) {
int U, V; cin >> U >> V;
adj[U].pb(V), adj[V].pb(U);
}
for(auto e : E) {
int U = e.ss;
for(auto v : adj[U]) {
if(!processed[v]) continue;
int V = findSet(v);
if(S[V] < S[U]) res[V] = 0;
if(!vis[V]) {
vis[V] = 1; D[U].pb(V);
}
}
for(auto v : adj[U]) {
if(!processed[v]) continue;
int V = findSet(v);
vis[V] = 0;
}
for(auto V : adj[U]) {
if(!processed[V]) continue;
unionSet(V, U);
}
int V = findSet(U);
processed[U] = 1;
}
dfs(E[N - 1].ss, 1);
for(int l = 1; l <= N; l++)
cout << res[l];
}
Compilation message
island.cpp: In function 'int32_t main()':
island.cpp:72:21: warning: unused variable 'V' [-Wunused-variable]
72 | int V = findSet(U);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14432 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14420 KB |
Output is correct |
4 |
Incorrect |
9 ms |
14548 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Incorrect |
153 ms |
39028 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Incorrect |
216 ms |
37808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Incorrect |
236 ms |
38792 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14432 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14420 KB |
Output is correct |
4 |
Incorrect |
9 ms |
14548 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |