#include <bits/stdc++.h>
using namespace std;
struct DSU
{
vector<int64_t> parent, weight;
vector<vector<int64_t>> components;
DSU(size_t n, vector<int64_t> const &s)
{
parent = vector<int64_t>(n, -1);
weight = vector<int64_t>(s.begin(), s.end());
components = vector<vector<int64_t>>(n);
for (size_t i = 0; i < n; i++)
components[i].push_back(i);
}
int root(int u)
{
return parent[u] < 0 ? u : parent[u] = root(parent[u]);
}
void merge(int u, int v)
{
u = root(u), v = root(v);
if (u == v)
return;
if (parent[u] > parent[v])
swap(u, v);
weight[u] += weight[v];
parent[u] += parent[v];
parent[v] = u;
components[u].insert(components[u].end(), components[v].begin(), components[v].end());
}
int64_t component_weight(int u) { return weight[root(u)]; }
};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
size_t n, m;
cin >> n >> m;
vector<int64_t> s(n);
for (int64_t &x : s)
cin >> x;
vector<pair<int64_t, unsigned>> nodes(n);
for (size_t i = 0; i < n; i++)
nodes[i] = {s[i], i};
sort(nodes.begin(), nodes.end());
vector<vector<unsigned>> g(n);
for (size_t i = 0; i < m; i++)
{
unsigned u, v;
cin >> u >> v;
g[u - 1].push_back(v - 1);
g[v - 1].push_back(u - 1);
}
DSU dsu(n, s);
for (auto const &[x, u] : nodes)
{
for (unsigned const &v : g[u])
{
if (s[v] <= x)
{
if (dsu.component_weight(v) >= x)
dsu.merge(u, v);
}
}
}
string ans(n, '0');
for (unsigned i : dsu.components[dsu.root(nodes.back().second)])
ans[i] = '1';
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
115 ms |
31180 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
130 ms |
30216 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
163 ms |
30844 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |