#include <bits/stdc++.h>
using namespace std;
int main()
{
size_t n, m;
cin >> n >> m;
vector<uint64_t> s(n);
uint64_t total_size = 0;
for (uint64_t &x : s)
cin >> x, total_size += x;
vector<pair<unsigned, unsigned>> p(n);
for (size_t i = 0; i < n; i++)
p[i] = {s[i], i};
sort(p.begin(), p.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);
}
vector<bool> z(n, 0);
for (auto const &[___, i] : p)
{
if (z[i])
continue;
priority_queue<pair<unsigned, unsigned>, vector<pair<unsigned, unsigned>>, greater<pair<unsigned, unsigned>>> q;
vector<bool> visited(n, 0);
visited[i] = 1;
uint64_t curr_size = s[i];
for (unsigned const &v : g[i])
q.emplace(s[v], v), visited[v] = 1;
while (!q.empty())
{
auto const [x, u] = q.top();
q.pop();
if (x > curr_size)
break;
curr_size += x;
for (unsigned const &v : g[u])
if (!visited[v])
{
q.emplace(s[v], v);
visited[v] = 1;
}
}
z[i] = curr_size == total_size;
if (z[i])
{
queue<unsigned> q;
for (unsigned const &v : g[i])
if (s[v] >= s[i] && !z[v])
q.push(v);
while (!q.empty())
{
z[q.front()] = 1;
for (unsigned const &v : g[q.front()])
if (s[v] >= s[q.front()] && !z[v])
q.push(v);
q.pop();
}
}
}
for (size_t i = 0; i < n; i++)
cout << (unsigned)z[i];
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
68 ms |
344 KB |
Output is correct |
5 |
Correct |
77 ms |
456 KB |
Output is correct |
6 |
Correct |
3 ms |
440 KB |
Output is correct |
7 |
Correct |
73 ms |
436 KB |
Output is correct |
8 |
Correct |
42 ms |
340 KB |
Output is correct |
9 |
Correct |
195 ms |
444 KB |
Output is correct |
10 |
Correct |
36 ms |
468 KB |
Output is correct |
11 |
Correct |
37 ms |
468 KB |
Output is correct |
12 |
Correct |
31 ms |
340 KB |
Output is correct |
13 |
Correct |
98 ms |
440 KB |
Output is correct |
14 |
Correct |
87 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
1079 ms |
18852 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1069 ms |
18900 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1085 ms |
18948 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
68 ms |
344 KB |
Output is correct |
5 |
Correct |
77 ms |
456 KB |
Output is correct |
6 |
Correct |
3 ms |
440 KB |
Output is correct |
7 |
Correct |
73 ms |
436 KB |
Output is correct |
8 |
Correct |
42 ms |
340 KB |
Output is correct |
9 |
Correct |
195 ms |
444 KB |
Output is correct |
10 |
Correct |
36 ms |
468 KB |
Output is correct |
11 |
Correct |
37 ms |
468 KB |
Output is correct |
12 |
Correct |
31 ms |
340 KB |
Output is correct |
13 |
Correct |
98 ms |
440 KB |
Output is correct |
14 |
Correct |
87 ms |
444 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
1079 ms |
18852 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |