#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int maxn = 200005;
int n, m;
long long people[maxn];
vector<int> g[maxn];
bool answer[maxn];
int parent[maxn];
vector<int> nodes_in_component[maxn];
long long sum_component[maxn];
int root(int x)
{
if (x == parent[x])
{
return x;
}
return parent[x] = root(parent[x]);
}
void connect(int x, int y)
{
x = root(x);
y = root(y);
if (nodes_in_component[x].size() < nodes_in_component[y].size())
{
swap(x, y);
}
sum_component[x] += sum_component[y];
for (auto node : nodes_in_component[y])
{
nodes_in_component[x].push_back(node);
}
parent[y] = x;
}
bool is_connected(int x, int y)
{
return root(x) == root(y);
}
pair<int, int> sorted_nodes[maxn];
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n >> m;
for (int i = 1; i <= n; ++i)
{
cin >> people[i];
answer[i] = true;
sorted_nodes[i] = make_pair(people[i], i);
}
for (int i = 1; i <= n; ++i)
{
sum_component[i] = people[i];
nodes_in_component[i].push_back(i);
parent[i] = i;
}
for (int i = 1; i <= m; ++i)
{
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 1; i <= n; ++i)
{
sort(g[i].begin(), g[i].end(), [&](int x, int y)
{
return people[x] <= people[y];
});
}
sort(sorted_nodes + 1, sorted_nodes + n + 1);
for (int i = 1; i <= n; ++i)
{
int node = sorted_nodes[i].second;
for (auto next_node : g[node])
{
if (people[node] < people[next_node])
{
continue;
}
int big_node = root(next_node);
if (sum_component[big_node] < people[node])
{
for (auto blanked_node : nodes_in_component[big_node])
{
answer[blanked_node] = false;
}
}
connect(node, big_node);
}
}
for (int i = 1; i <= n; ++i)
{
cout << answer[i];
}
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9812 KB |
Output is correct |
2 |
Correct |
6 ms |
9736 KB |
Output is correct |
3 |
Correct |
6 ms |
9736 KB |
Output is correct |
4 |
Runtime error |
16 ms |
20456 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9736 KB |
Output is correct |
3 |
Runtime error |
111 ms |
61736 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9736 KB |
Output is correct |
2 |
Correct |
170 ms |
39664 KB |
Output is correct |
3 |
Incorrect |
219 ms |
39596 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Runtime error |
145 ms |
61032 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9812 KB |
Output is correct |
2 |
Correct |
6 ms |
9736 KB |
Output is correct |
3 |
Correct |
6 ms |
9736 KB |
Output is correct |
4 |
Runtime error |
16 ms |
20456 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |