#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;
}
}
if (is_connected(node, big_node) == false)
{
connect(node, big_node);
}
}
}
for (int i = 1; i <= n; ++i)
{
cout << answer[i];
}
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9724 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9812 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
5 ms |
9812 KB |
Output is correct |
7 |
Correct |
5 ms |
9812 KB |
Output is correct |
8 |
Correct |
5 ms |
9812 KB |
Output is correct |
9 |
Correct |
5 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9940 KB |
Output is correct |
11 |
Correct |
7 ms |
9940 KB |
Output is correct |
12 |
Correct |
5 ms |
9940 KB |
Output is correct |
13 |
Correct |
5 ms |
9940 KB |
Output is correct |
14 |
Correct |
6 ms |
9940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
105 ms |
29416 KB |
Output is correct |
4 |
Correct |
97 ms |
29092 KB |
Output is correct |
5 |
Correct |
133 ms |
32636 KB |
Output is correct |
6 |
Correct |
166 ms |
33452 KB |
Output is correct |
7 |
Correct |
136 ms |
33468 KB |
Output is correct |
8 |
Correct |
122 ms |
29124 KB |
Output is correct |
9 |
Correct |
115 ms |
37660 KB |
Output is correct |
10 |
Correct |
129 ms |
30380 KB |
Output is correct |
11 |
Correct |
109 ms |
30232 KB |
Output is correct |
12 |
Correct |
134 ms |
32996 KB |
Output is correct |
13 |
Correct |
95 ms |
31924 KB |
Output is correct |
14 |
Correct |
100 ms |
32184 KB |
Output is correct |
15 |
Correct |
106 ms |
33512 KB |
Output is correct |
16 |
Correct |
81 ms |
32580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
164 ms |
35384 KB |
Output is correct |
3 |
Correct |
166 ms |
35144 KB |
Output is correct |
4 |
Correct |
114 ms |
29064 KB |
Output is correct |
5 |
Correct |
111 ms |
29336 KB |
Output is correct |
6 |
Correct |
169 ms |
35256 KB |
Output is correct |
7 |
Correct |
118 ms |
29052 KB |
Output is correct |
8 |
Correct |
117 ms |
29020 KB |
Output is correct |
9 |
Correct |
78 ms |
28800 KB |
Output is correct |
10 |
Correct |
109 ms |
29072 KB |
Output is correct |
11 |
Correct |
152 ms |
30296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
175 ms |
30992 KB |
Output is correct |
3 |
Correct |
175 ms |
31600 KB |
Output is correct |
4 |
Correct |
172 ms |
32592 KB |
Output is correct |
5 |
Correct |
168 ms |
31852 KB |
Output is correct |
6 |
Correct |
158 ms |
29780 KB |
Output is correct |
7 |
Correct |
101 ms |
30236 KB |
Output is correct |
8 |
Correct |
79 ms |
32336 KB |
Output is correct |
9 |
Correct |
88 ms |
23724 KB |
Output is correct |
10 |
Correct |
170 ms |
35544 KB |
Output is correct |
11 |
Correct |
143 ms |
33184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9724 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9812 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
5 ms |
9812 KB |
Output is correct |
7 |
Correct |
5 ms |
9812 KB |
Output is correct |
8 |
Correct |
5 ms |
9812 KB |
Output is correct |
9 |
Correct |
5 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9940 KB |
Output is correct |
11 |
Correct |
7 ms |
9940 KB |
Output is correct |
12 |
Correct |
5 ms |
9940 KB |
Output is correct |
13 |
Correct |
5 ms |
9940 KB |
Output is correct |
14 |
Correct |
6 ms |
9940 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
4 ms |
9684 KB |
Output is correct |
17 |
Correct |
105 ms |
29416 KB |
Output is correct |
18 |
Correct |
97 ms |
29092 KB |
Output is correct |
19 |
Correct |
133 ms |
32636 KB |
Output is correct |
20 |
Correct |
166 ms |
33452 KB |
Output is correct |
21 |
Correct |
136 ms |
33468 KB |
Output is correct |
22 |
Correct |
122 ms |
29124 KB |
Output is correct |
23 |
Correct |
115 ms |
37660 KB |
Output is correct |
24 |
Correct |
129 ms |
30380 KB |
Output is correct |
25 |
Correct |
109 ms |
30232 KB |
Output is correct |
26 |
Correct |
134 ms |
32996 KB |
Output is correct |
27 |
Correct |
95 ms |
31924 KB |
Output is correct |
28 |
Correct |
100 ms |
32184 KB |
Output is correct |
29 |
Correct |
106 ms |
33512 KB |
Output is correct |
30 |
Correct |
81 ms |
32580 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
164 ms |
35384 KB |
Output is correct |
33 |
Correct |
166 ms |
35144 KB |
Output is correct |
34 |
Correct |
114 ms |
29064 KB |
Output is correct |
35 |
Correct |
111 ms |
29336 KB |
Output is correct |
36 |
Correct |
169 ms |
35256 KB |
Output is correct |
37 |
Correct |
118 ms |
29052 KB |
Output is correct |
38 |
Correct |
117 ms |
29020 KB |
Output is correct |
39 |
Correct |
78 ms |
28800 KB |
Output is correct |
40 |
Correct |
109 ms |
29072 KB |
Output is correct |
41 |
Correct |
152 ms |
30296 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
175 ms |
30992 KB |
Output is correct |
44 |
Correct |
175 ms |
31600 KB |
Output is correct |
45 |
Correct |
172 ms |
32592 KB |
Output is correct |
46 |
Correct |
168 ms |
31852 KB |
Output is correct |
47 |
Correct |
158 ms |
29780 KB |
Output is correct |
48 |
Correct |
101 ms |
30236 KB |
Output is correct |
49 |
Correct |
79 ms |
32336 KB |
Output is correct |
50 |
Correct |
88 ms |
23724 KB |
Output is correct |
51 |
Correct |
170 ms |
35544 KB |
Output is correct |
52 |
Correct |
143 ms |
33184 KB |
Output is correct |
53 |
Correct |
4 ms |
9684 KB |
Output is correct |
54 |
Correct |
4 ms |
9684 KB |
Output is correct |
55 |
Correct |
4 ms |
9712 KB |
Output is correct |
56 |
Correct |
6 ms |
9876 KB |
Output is correct |
57 |
Correct |
5 ms |
9940 KB |
Output is correct |
58 |
Correct |
5 ms |
9940 KB |
Output is correct |
59 |
Correct |
5 ms |
9940 KB |
Output is correct |
60 |
Correct |
5 ms |
9812 KB |
Output is correct |
61 |
Correct |
5 ms |
9940 KB |
Output is correct |
62 |
Correct |
5 ms |
9940 KB |
Output is correct |
63 |
Correct |
5 ms |
9940 KB |
Output is correct |
64 |
Correct |
5 ms |
10004 KB |
Output is correct |
65 |
Correct |
5 ms |
9868 KB |
Output is correct |
66 |
Correct |
5 ms |
9940 KB |
Output is correct |
67 |
Correct |
134 ms |
33864 KB |
Output is correct |
68 |
Correct |
99 ms |
32148 KB |
Output is correct |
69 |
Correct |
127 ms |
36868 KB |
Output is correct |
70 |
Correct |
138 ms |
37788 KB |
Output is correct |
71 |
Correct |
141 ms |
37876 KB |
Output is correct |
72 |
Correct |
126 ms |
33548 KB |
Output is correct |
73 |
Correct |
115 ms |
42044 KB |
Output is correct |
74 |
Correct |
112 ms |
33772 KB |
Output is correct |
75 |
Correct |
110 ms |
33644 KB |
Output is correct |
76 |
Correct |
129 ms |
33060 KB |
Output is correct |
77 |
Correct |
93 ms |
31924 KB |
Output is correct |
78 |
Correct |
100 ms |
32124 KB |
Output is correct |
79 |
Correct |
100 ms |
33408 KB |
Output is correct |
80 |
Correct |
78 ms |
32664 KB |
Output is correct |
81 |
Correct |
174 ms |
39736 KB |
Output is correct |
82 |
Correct |
164 ms |
39632 KB |
Output is correct |
83 |
Correct |
118 ms |
33528 KB |
Output is correct |
84 |
Correct |
121 ms |
32352 KB |
Output is correct |
85 |
Correct |
163 ms |
39704 KB |
Output is correct |
86 |
Correct |
119 ms |
33468 KB |
Output is correct |
87 |
Correct |
120 ms |
33444 KB |
Output is correct |
88 |
Correct |
122 ms |
32836 KB |
Output is correct |
89 |
Correct |
129 ms |
33272 KB |
Output is correct |
90 |
Correct |
173 ms |
35404 KB |
Output is correct |
91 |
Correct |
180 ms |
36040 KB |
Output is correct |
92 |
Correct |
173 ms |
37052 KB |
Output is correct |
93 |
Correct |
165 ms |
36224 KB |
Output is correct |
94 |
Correct |
147 ms |
33832 KB |
Output is correct |
95 |
Correct |
103 ms |
34560 KB |
Output is correct |
96 |
Correct |
80 ms |
32352 KB |
Output is correct |
97 |
Correct |
86 ms |
23752 KB |
Output is correct |
98 |
Correct |
145 ms |
35536 KB |
Output is correct |
99 |
Correct |
145 ms |
33120 KB |
Output is correct |
100 |
Correct |
34 ms |
14084 KB |
Output is correct |
101 |
Correct |
176 ms |
36896 KB |
Output is correct |
102 |
Correct |
126 ms |
29780 KB |
Output is correct |
103 |
Correct |
146 ms |
30884 KB |
Output is correct |
104 |
Correct |
184 ms |
34688 KB |
Output is correct |