This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, m, a[maxn], fa[maxn], sum[maxn];
bool vis[maxn], ans[maxn];
vector<int> G[maxn], Q[maxn];
int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
vector<array<int, 2>> V;
for (int i = 1; i <= n; i++) {
cin >> a[i], V.push_back({a[i], i});
}
while (m--) {
int u, v;
cin >> u >> v;
G[u].push_back(v), G[v].push_back(u);
}
sort(V.begin(), V.end());
for (int i = 1; i <= n; i++) {
int j = lower_bound(V.begin(), V.end(), array<int, 2>{a[i] + 1, 0}) - V.begin() - 1;
Q[j].push_back(i);
}
iota(fa + 1, fa + n + 1, 1);
copy(a + 1, a + n + 1, sum + 1);
int lst = 0;
for (int i = 0; i < V.size(); i++) {
vis[V[i][1]] = 1;
for (int j : G[V[i][1]]) if (vis[j]) {
int x = find(V[i][1]), y = find(j);
if (x ^ y) fa[y] = x, sum[x] = min((int)1e9, sum[x] + sum[y]);
}
if (i + 1 < V.size() && V[i][0] == V[i + 1][0]) continue;
for (int x : Q[i]) {
int y = lower_bound(V.begin(), V.end(), array<int, 2>{sum[find(x)] + 1, 0}) - V.begin() - 1;
if (i < y) Q[y].push_back(x);
else if (i + 1 == V.size()) ans[x] = 1;
}
}
for (int i = 1; i <= n; i++) {
cout << (ans[i] ? '1' : '0');
}
return 0;
}
Compilation message (stderr)
island.cpp: In function 'int main()':
island.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < V.size(); i++) {
| ~~^~~~~~~~~~
island.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if (i + 1 < V.size() && V[i][0] == V[i + 1][0]) continue;
| ~~~~~~^~~~~~~~~~
island.cpp:43:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | else if (i + 1 == V.size()) ans[x] = 1;
| ~~~~~~^~~~~~~~~~~
island.cpp:32:9: warning: unused variable 'lst' [-Wunused-variable]
32 | int lst = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |