#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9732 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9940 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
5 ms |
9940 KB |
Output is correct |
7 |
Correct |
7 ms |
9940 KB |
Output is correct |
8 |
Correct |
5 ms |
9876 KB |
Output is correct |
9 |
Correct |
5 ms |
9872 KB |
Output is correct |
10 |
Correct |
7 ms |
10000 KB |
Output is correct |
11 |
Correct |
5 ms |
9940 KB |
Output is correct |
12 |
Correct |
5 ms |
9932 KB |
Output is correct |
13 |
Correct |
6 ms |
9940 KB |
Output is correct |
14 |
Correct |
6 ms |
9940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9736 KB |
Output is correct |
3 |
Correct |
140 ms |
33780 KB |
Output is correct |
4 |
Correct |
104 ms |
32100 KB |
Output is correct |
5 |
Correct |
153 ms |
36900 KB |
Output is correct |
6 |
Correct |
134 ms |
37724 KB |
Output is correct |
7 |
Correct |
140 ms |
37880 KB |
Output is correct |
8 |
Correct |
150 ms |
33480 KB |
Output is correct |
9 |
Correct |
131 ms |
42036 KB |
Output is correct |
10 |
Correct |
134 ms |
33700 KB |
Output is correct |
11 |
Correct |
121 ms |
33564 KB |
Output is correct |
12 |
Correct |
144 ms |
32980 KB |
Output is correct |
13 |
Correct |
137 ms |
31940 KB |
Output is correct |
14 |
Correct |
128 ms |
32164 KB |
Output is correct |
15 |
Correct |
103 ms |
33416 KB |
Output is correct |
16 |
Correct |
104 ms |
32604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9740 KB |
Output is correct |
2 |
Correct |
190 ms |
39776 KB |
Output is correct |
3 |
Correct |
166 ms |
39632 KB |
Output is correct |
4 |
Correct |
120 ms |
33524 KB |
Output is correct |
5 |
Correct |
105 ms |
32228 KB |
Output is correct |
6 |
Correct |
205 ms |
39776 KB |
Output is correct |
7 |
Correct |
132 ms |
33508 KB |
Output is correct |
8 |
Correct |
119 ms |
33488 KB |
Output is correct |
9 |
Correct |
79 ms |
32516 KB |
Output is correct |
10 |
Correct |
107 ms |
32824 KB |
Output is correct |
11 |
Correct |
139 ms |
33356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9736 KB |
Output is correct |
2 |
Correct |
184 ms |
35352 KB |
Output is correct |
3 |
Correct |
169 ms |
36088 KB |
Output is correct |
4 |
Correct |
192 ms |
37128 KB |
Output is correct |
5 |
Correct |
199 ms |
36308 KB |
Output is correct |
6 |
Correct |
168 ms |
33924 KB |
Output is correct |
7 |
Correct |
103 ms |
34580 KB |
Output is correct |
8 |
Correct |
82 ms |
32264 KB |
Output is correct |
9 |
Correct |
84 ms |
23692 KB |
Output is correct |
10 |
Correct |
145 ms |
35624 KB |
Output is correct |
11 |
Correct |
126 ms |
33072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9732 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9940 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
5 ms |
9940 KB |
Output is correct |
7 |
Correct |
7 ms |
9940 KB |
Output is correct |
8 |
Correct |
5 ms |
9876 KB |
Output is correct |
9 |
Correct |
5 ms |
9872 KB |
Output is correct |
10 |
Correct |
7 ms |
10000 KB |
Output is correct |
11 |
Correct |
5 ms |
9940 KB |
Output is correct |
12 |
Correct |
5 ms |
9932 KB |
Output is correct |
13 |
Correct |
6 ms |
9940 KB |
Output is correct |
14 |
Correct |
6 ms |
9940 KB |
Output is correct |
15 |
Correct |
6 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9736 KB |
Output is correct |
17 |
Correct |
140 ms |
33780 KB |
Output is correct |
18 |
Correct |
104 ms |
32100 KB |
Output is correct |
19 |
Correct |
153 ms |
36900 KB |
Output is correct |
20 |
Correct |
134 ms |
37724 KB |
Output is correct |
21 |
Correct |
140 ms |
37880 KB |
Output is correct |
22 |
Correct |
150 ms |
33480 KB |
Output is correct |
23 |
Correct |
131 ms |
42036 KB |
Output is correct |
24 |
Correct |
134 ms |
33700 KB |
Output is correct |
25 |
Correct |
121 ms |
33564 KB |
Output is correct |
26 |
Correct |
144 ms |
32980 KB |
Output is correct |
27 |
Correct |
137 ms |
31940 KB |
Output is correct |
28 |
Correct |
128 ms |
32164 KB |
Output is correct |
29 |
Correct |
103 ms |
33416 KB |
Output is correct |
30 |
Correct |
104 ms |
32604 KB |
Output is correct |
31 |
Correct |
6 ms |
9740 KB |
Output is correct |
32 |
Correct |
190 ms |
39776 KB |
Output is correct |
33 |
Correct |
166 ms |
39632 KB |
Output is correct |
34 |
Correct |
120 ms |
33524 KB |
Output is correct |
35 |
Correct |
105 ms |
32228 KB |
Output is correct |
36 |
Correct |
205 ms |
39776 KB |
Output is correct |
37 |
Correct |
132 ms |
33508 KB |
Output is correct |
38 |
Correct |
119 ms |
33488 KB |
Output is correct |
39 |
Correct |
79 ms |
32516 KB |
Output is correct |
40 |
Correct |
107 ms |
32824 KB |
Output is correct |
41 |
Correct |
139 ms |
33356 KB |
Output is correct |
42 |
Correct |
5 ms |
9736 KB |
Output is correct |
43 |
Correct |
184 ms |
35352 KB |
Output is correct |
44 |
Correct |
169 ms |
36088 KB |
Output is correct |
45 |
Correct |
192 ms |
37128 KB |
Output is correct |
46 |
Correct |
199 ms |
36308 KB |
Output is correct |
47 |
Correct |
168 ms |
33924 KB |
Output is correct |
48 |
Correct |
103 ms |
34580 KB |
Output is correct |
49 |
Correct |
82 ms |
32264 KB |
Output is correct |
50 |
Correct |
84 ms |
23692 KB |
Output is correct |
51 |
Correct |
145 ms |
35624 KB |
Output is correct |
52 |
Correct |
126 ms |
33072 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 |
9684 KB |
Output is correct |
56 |
Correct |
6 ms |
9940 KB |
Output is correct |
57 |
Correct |
5 ms |
9940 KB |
Output is correct |
58 |
Correct |
5 ms |
9876 KB |
Output is correct |
59 |
Correct |
6 ms |
9872 KB |
Output is correct |
60 |
Correct |
5 ms |
9812 KB |
Output is correct |
61 |
Correct |
5 ms |
9876 KB |
Output is correct |
62 |
Correct |
5 ms |
10004 KB |
Output is correct |
63 |
Correct |
5 ms |
9940 KB |
Output is correct |
64 |
Correct |
5 ms |
9916 KB |
Output is correct |
65 |
Correct |
5 ms |
9940 KB |
Output is correct |
66 |
Correct |
5 ms |
9876 KB |
Output is correct |
67 |
Correct |
110 ms |
33860 KB |
Output is correct |
68 |
Correct |
106 ms |
32368 KB |
Output is correct |
69 |
Correct |
125 ms |
36904 KB |
Output is correct |
70 |
Correct |
152 ms |
37800 KB |
Output is correct |
71 |
Correct |
140 ms |
37904 KB |
Output is correct |
72 |
Correct |
145 ms |
33428 KB |
Output is correct |
73 |
Correct |
121 ms |
42068 KB |
Output is correct |
74 |
Correct |
106 ms |
33816 KB |
Output is correct |
75 |
Correct |
107 ms |
33652 KB |
Output is correct |
76 |
Correct |
128 ms |
33048 KB |
Output is correct |
77 |
Correct |
89 ms |
31892 KB |
Output is correct |
78 |
Correct |
95 ms |
32196 KB |
Output is correct |
79 |
Correct |
135 ms |
33472 KB |
Output is correct |
80 |
Correct |
77 ms |
32556 KB |
Output is correct |
81 |
Correct |
161 ms |
39740 KB |
Output is correct |
82 |
Correct |
162 ms |
39612 KB |
Output is correct |
83 |
Correct |
125 ms |
33452 KB |
Output is correct |
84 |
Correct |
95 ms |
32240 KB |
Output is correct |
85 |
Correct |
207 ms |
39692 KB |
Output is correct |
86 |
Correct |
112 ms |
33516 KB |
Output is correct |
87 |
Correct |
120 ms |
33528 KB |
Output is correct |
88 |
Correct |
125 ms |
32752 KB |
Output is correct |
89 |
Correct |
138 ms |
33324 KB |
Output is correct |
90 |
Correct |
171 ms |
35376 KB |
Output is correct |
91 |
Correct |
207 ms |
36036 KB |
Output is correct |
92 |
Correct |
185 ms |
37036 KB |
Output is correct |
93 |
Correct |
166 ms |
36328 KB |
Output is correct |
94 |
Correct |
137 ms |
33824 KB |
Output is correct |
95 |
Correct |
114 ms |
34548 KB |
Output is correct |
96 |
Correct |
89 ms |
32308 KB |
Output is correct |
97 |
Correct |
107 ms |
23688 KB |
Output is correct |
98 |
Correct |
164 ms |
35656 KB |
Output is correct |
99 |
Correct |
135 ms |
33040 KB |
Output is correct |
100 |
Correct |
35 ms |
14180 KB |
Output is correct |
101 |
Correct |
207 ms |
36852 KB |
Output is correct |
102 |
Correct |
131 ms |
29776 KB |
Output is correct |
103 |
Correct |
154 ms |
30808 KB |
Output is correct |
104 |
Correct |
177 ms |
34688 KB |
Output is correct |