#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma region dalykai
template <typename F>
void _debug(F f)
{
f();
}
#ifndef _AAAAAAAAA
#define debug(x)
#else
#define debug(x) _debug(x)
#endif
using p32 = pair<int, int>;
using p32u = pair<uint32_t, uint32_t>;
using p64 = pair<int64_t, int64_t>;
using p64u = pair<uint64_t, uint64_t>;
using vi16 = vector<int16_t>;
using vi16u = vector<uint16_t>;
using vi32 = vector<int>;
using vi32u = vector<uint32_t>;
using vi64 = vector<int64_t>;
using vi64u = vector<uint64_t>;
using vp32 = vector<p32>;
using vp32u = vector<p32u>;
using vp64 = vector<p64>;
using vp64u = vector<p64u>;
using vvi32 = vector<vi32>;
using vvi32u = vector<vi32u>;
using vvi64 = vector<vi64>;
using vvi64u = vector<vi64u>;
using vvp32 = vector<vp32>;
using vvp32u = vector<vp32u>;
using vvp64 = vector<vp64>;
using vvp64u = vector<vp64u>;
using f80 = long double;
#pragma endregion
using state_t = bitset<(int)2e5>;
struct dsu_t
{
vi32 parent;
vi64 weight;
state_t marked;
dsu_t(int n) : parent(n), weight(n)
{
iota(parent.begin(), parent.end(), 0);
}
int find_set(int a)
{
if (parent[a] == a)
{
return a;
}
int p = a;
while (p != parent[p])
{
if (marked[p])
{
marked[a] = true;
}
p = parent[p];
}
return p;
}
void unite(int a, int b)
{
a = find_set(a);
b = find_set(b);
if (a == b)
{
return;
}
if (weight[a] < weight[b])
{
swap(a, b);
}
parent[b] = a;
weight[a] += weight[b];
}
};
int main()
{
#ifndef _AAAAAAAAA
ios_base::sync_with_stdio(false);
cin.tie(0);
#else
freopen("sala.in", "r", stdin);
#ifndef __linux__
atexit([]()
{
freopen("con", "r", stdin);
system("pause"); });
#endif
#endif
int v, e;
cin >> v >> e;
vi64 weight(v);
for (auto &w : weight)
{
cin >> w;
}
vi32 order(v);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(),
[&](int a, int b)
{
return weight[a] < weight[b];
//
});
vvi32 adj(v);
for (int i = 0; i < e; i++)
{
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
dsu_t dsu(v);
dsu.weight = weight;
for (auto &i : order)
{
for (auto &next : adj[i])
{
if (weight[next] > weight[i])
{
continue;
}
next = dsu.find_set(next);
if (dsu.weight[next] < weight[i])
{
dsu.marked[next] = true;
}
dsu.unite(i, next);
}
}
for (int i = 0; i < v; i++)
{
dsu.find_set(i);
cout << !dsu.marked[i];
}
cout << '\n';
return 0;
}
Compilation message
island.cpp:8: warning: ignoring '#pragma region dalykai' [-Wunknown-pragmas]
8 | #pragma region dalykai
|
island.cpp:43: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
43 | #pragma endregion
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
144 ms |
16232 KB |
Output is correct |
4 |
Correct |
127 ms |
16144 KB |
Output is correct |
5 |
Correct |
128 ms |
15664 KB |
Output is correct |
6 |
Correct |
155 ms |
16148 KB |
Output is correct |
7 |
Correct |
146 ms |
16204 KB |
Output is correct |
8 |
Correct |
138 ms |
16220 KB |
Output is correct |
9 |
Correct |
144 ms |
16116 KB |
Output is correct |
10 |
Correct |
96 ms |
16920 KB |
Output is correct |
11 |
Correct |
102 ms |
16976 KB |
Output is correct |
12 |
Correct |
159 ms |
16248 KB |
Output is correct |
13 |
Correct |
114 ms |
16172 KB |
Output is correct |
14 |
Correct |
130 ms |
16076 KB |
Output is correct |
15 |
Correct |
129 ms |
16120 KB |
Output is correct |
16 |
Correct |
75 ms |
15976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
162 ms |
15996 KB |
Output is correct |
3 |
Correct |
165 ms |
16132 KB |
Output is correct |
4 |
Correct |
133 ms |
16172 KB |
Output is correct |
5 |
Correct |
149 ms |
16124 KB |
Output is correct |
6 |
Correct |
158 ms |
16204 KB |
Output is correct |
7 |
Correct |
142 ms |
16112 KB |
Output is correct |
8 |
Correct |
171 ms |
16088 KB |
Output is correct |
9 |
Correct |
84 ms |
15972 KB |
Output is correct |
10 |
Correct |
128 ms |
16084 KB |
Output is correct |
11 |
Correct |
124 ms |
16124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
183 ms |
16152 KB |
Output is correct |
3 |
Correct |
189 ms |
16128 KB |
Output is correct |
4 |
Correct |
185 ms |
16264 KB |
Output is correct |
5 |
Correct |
172 ms |
16124 KB |
Output is correct |
6 |
Correct |
158 ms |
15436 KB |
Output is correct |
7 |
Correct |
106 ms |
16904 KB |
Output is correct |
8 |
Correct |
98 ms |
16100 KB |
Output is correct |
9 |
Correct |
107 ms |
9224 KB |
Output is correct |
10 |
Correct |
136 ms |
16176 KB |
Output is correct |
11 |
Correct |
140 ms |
16116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
144 ms |
16232 KB |
Output is correct |
18 |
Correct |
127 ms |
16144 KB |
Output is correct |
19 |
Correct |
128 ms |
15664 KB |
Output is correct |
20 |
Correct |
155 ms |
16148 KB |
Output is correct |
21 |
Correct |
146 ms |
16204 KB |
Output is correct |
22 |
Correct |
138 ms |
16220 KB |
Output is correct |
23 |
Correct |
144 ms |
16116 KB |
Output is correct |
24 |
Correct |
96 ms |
16920 KB |
Output is correct |
25 |
Correct |
102 ms |
16976 KB |
Output is correct |
26 |
Correct |
159 ms |
16248 KB |
Output is correct |
27 |
Correct |
114 ms |
16172 KB |
Output is correct |
28 |
Correct |
130 ms |
16076 KB |
Output is correct |
29 |
Correct |
129 ms |
16120 KB |
Output is correct |
30 |
Correct |
75 ms |
15976 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
162 ms |
15996 KB |
Output is correct |
33 |
Correct |
165 ms |
16132 KB |
Output is correct |
34 |
Correct |
133 ms |
16172 KB |
Output is correct |
35 |
Correct |
149 ms |
16124 KB |
Output is correct |
36 |
Correct |
158 ms |
16204 KB |
Output is correct |
37 |
Correct |
142 ms |
16112 KB |
Output is correct |
38 |
Correct |
171 ms |
16088 KB |
Output is correct |
39 |
Correct |
84 ms |
15972 KB |
Output is correct |
40 |
Correct |
128 ms |
16084 KB |
Output is correct |
41 |
Correct |
124 ms |
16124 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
183 ms |
16152 KB |
Output is correct |
44 |
Correct |
189 ms |
16128 KB |
Output is correct |
45 |
Correct |
185 ms |
16264 KB |
Output is correct |
46 |
Correct |
172 ms |
16124 KB |
Output is correct |
47 |
Correct |
158 ms |
15436 KB |
Output is correct |
48 |
Correct |
106 ms |
16904 KB |
Output is correct |
49 |
Correct |
98 ms |
16100 KB |
Output is correct |
50 |
Correct |
107 ms |
9224 KB |
Output is correct |
51 |
Correct |
136 ms |
16176 KB |
Output is correct |
52 |
Correct |
140 ms |
16116 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
340 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
2 ms |
468 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
468 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
1 ms |
468 KB |
Output is correct |
62 |
Correct |
2 ms |
468 KB |
Output is correct |
63 |
Correct |
1 ms |
468 KB |
Output is correct |
64 |
Correct |
1 ms |
596 KB |
Output is correct |
65 |
Correct |
1 ms |
468 KB |
Output is correct |
66 |
Correct |
1 ms |
428 KB |
Output is correct |
67 |
Correct |
121 ms |
16132 KB |
Output is correct |
68 |
Correct |
130 ms |
16204 KB |
Output is correct |
69 |
Correct |
150 ms |
15664 KB |
Output is correct |
70 |
Correct |
168 ms |
16140 KB |
Output is correct |
71 |
Correct |
149 ms |
16220 KB |
Output is correct |
72 |
Correct |
164 ms |
16332 KB |
Output is correct |
73 |
Correct |
168 ms |
16176 KB |
Output is correct |
74 |
Correct |
96 ms |
16932 KB |
Output is correct |
75 |
Correct |
97 ms |
16916 KB |
Output is correct |
76 |
Correct |
143 ms |
16188 KB |
Output is correct |
77 |
Correct |
130 ms |
16136 KB |
Output is correct |
78 |
Correct |
136 ms |
16140 KB |
Output is correct |
79 |
Correct |
120 ms |
16076 KB |
Output is correct |
80 |
Correct |
81 ms |
15996 KB |
Output is correct |
81 |
Correct |
155 ms |
15980 KB |
Output is correct |
82 |
Correct |
178 ms |
16140 KB |
Output is correct |
83 |
Correct |
126 ms |
16176 KB |
Output is correct |
84 |
Correct |
150 ms |
16156 KB |
Output is correct |
85 |
Correct |
205 ms |
16124 KB |
Output is correct |
86 |
Correct |
146 ms |
16092 KB |
Output is correct |
87 |
Correct |
152 ms |
16132 KB |
Output is correct |
88 |
Correct |
114 ms |
16180 KB |
Output is correct |
89 |
Correct |
129 ms |
16156 KB |
Output is correct |
90 |
Correct |
168 ms |
16104 KB |
Output is correct |
91 |
Correct |
162 ms |
16100 KB |
Output is correct |
92 |
Correct |
152 ms |
16180 KB |
Output is correct |
93 |
Correct |
160 ms |
16128 KB |
Output is correct |
94 |
Correct |
138 ms |
15400 KB |
Output is correct |
95 |
Correct |
120 ms |
16872 KB |
Output is correct |
96 |
Correct |
91 ms |
16120 KB |
Output is correct |
97 |
Correct |
88 ms |
9160 KB |
Output is correct |
98 |
Correct |
138 ms |
16180 KB |
Output is correct |
99 |
Correct |
148 ms |
16068 KB |
Output is correct |
100 |
Correct |
35 ms |
2700 KB |
Output is correct |
101 |
Correct |
175 ms |
16256 KB |
Output is correct |
102 |
Correct |
167 ms |
12904 KB |
Output is correct |
103 |
Correct |
168 ms |
13668 KB |
Output is correct |
104 |
Correct |
177 ms |
15924 KB |
Output is correct |