#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5+5;
int n, m, a[N], p[N], sz[N], dp[N];
vector<int> adj[N];
pair<int, int> s[N];
set<pair<int, int>> st[N];
bitset<N> ok;
int findSet(int x) {
return p[x] = (p[x] == x ? x : findSet(p[x]));
}
void unite(int x, int y) {
int X = x;
x = findSet(x);
y = findSet(y);
if (x == y) return;
if (st[x].size() < st[y].size()) {
swap(x, y);
}
p[y] = x;
sz[x] += sz[y];
for (pair<int, int> z : st[y]) {
st[x].insert(z);
}
while (*st[x].begin() <= make_pair(a[X], X)) st[x].erase(st[x].begin());
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
a[n] = INT_MAX;
for (int i = 0; i < n; i++) {
cin >> a[i];
s[i] = make_pair(a[i], i);
}
sort(s, s+n);
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--; y--;
adj[x].push_back(y);
adj[y].push_back(x);
}
for (int i = 0; i < n; i++) {
p[i] = i;
sz[i] = a[i];
st[i].insert(make_pair(INT_MAX, n));
for (int& j : adj[i]) {
if (make_pair(a[j], j) > make_pair(a[i], i)) st[i].insert(make_pair(a[j], j));
}
}
for (int i = 0; i < n; i++) {
int x = s[i].second;
for (int& j : adj[x]) {
if (make_pair(a[j], j) < make_pair(a[x], x)) unite(x, j);
}
int y = findSet(x);
int z = sz[y];
int nwMn = st[y].begin()->second;
if (nwMn == n) {
dp[x] = x;
ok[x] = 1;
}
else if (a[nwMn] <= z) {
dp[x] = nwMn;
}
else {
dp[x] = x;
}
}
for (int i = n-1; i >= 0; i--) {
int x = s[i].second;
ok[x] = ok[dp[x]];
}
for (int i = 0; i < n; i++) {
cout << ok[i];
}
cout << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14400 KB |
Output is correct |
4 |
Correct |
8 ms |
14864 KB |
Output is correct |
5 |
Correct |
8 ms |
14932 KB |
Output is correct |
6 |
Correct |
8 ms |
14784 KB |
Output is correct |
7 |
Correct |
10 ms |
14804 KB |
Output is correct |
8 |
Correct |
8 ms |
14804 KB |
Output is correct |
9 |
Correct |
8 ms |
14932 KB |
Output is correct |
10 |
Correct |
8 ms |
14804 KB |
Output is correct |
11 |
Correct |
8 ms |
14828 KB |
Output is correct |
12 |
Correct |
8 ms |
14804 KB |
Output is correct |
13 |
Correct |
8 ms |
14832 KB |
Output is correct |
14 |
Correct |
9 ms |
14924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
155 ms |
56320 KB |
Output is correct |
4 |
Correct |
163 ms |
59560 KB |
Output is correct |
5 |
Correct |
190 ms |
59140 KB |
Output is correct |
6 |
Correct |
203 ms |
60632 KB |
Output is correct |
7 |
Correct |
194 ms |
60620 KB |
Output is correct |
8 |
Correct |
226 ms |
64436 KB |
Output is correct |
9 |
Correct |
158 ms |
61912 KB |
Output is correct |
10 |
Correct |
179 ms |
60396 KB |
Output is correct |
11 |
Correct |
220 ms |
60292 KB |
Output is correct |
12 |
Correct |
259 ms |
61672 KB |
Output is correct |
13 |
Correct |
136 ms |
58176 KB |
Output is correct |
14 |
Correct |
145 ms |
58368 KB |
Output is correct |
15 |
Correct |
150 ms |
59704 KB |
Output is correct |
16 |
Correct |
113 ms |
58684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
231 ms |
55004 KB |
Output is correct |
3 |
Correct |
232 ms |
59680 KB |
Output is correct |
4 |
Correct |
170 ms |
59764 KB |
Output is correct |
5 |
Correct |
138 ms |
58200 KB |
Output is correct |
6 |
Correct |
222 ms |
59724 KB |
Output is correct |
7 |
Correct |
176 ms |
59752 KB |
Output is correct |
8 |
Correct |
170 ms |
59780 KB |
Output is correct |
9 |
Correct |
107 ms |
58612 KB |
Output is correct |
10 |
Correct |
156 ms |
59772 KB |
Output is correct |
11 |
Correct |
196 ms |
58452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
283 ms |
56412 KB |
Output is correct |
3 |
Correct |
278 ms |
60584 KB |
Output is correct |
4 |
Correct |
321 ms |
60944 KB |
Output is correct |
5 |
Correct |
236 ms |
60824 KB |
Output is correct |
6 |
Correct |
239 ms |
60984 KB |
Output is correct |
7 |
Correct |
189 ms |
61240 KB |
Output is correct |
8 |
Correct |
144 ms |
66380 KB |
Output is correct |
9 |
Correct |
185 ms |
50192 KB |
Output is correct |
10 |
Correct |
257 ms |
59416 KB |
Output is correct |
11 |
Correct |
188 ms |
58464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14400 KB |
Output is correct |
4 |
Correct |
8 ms |
14864 KB |
Output is correct |
5 |
Correct |
8 ms |
14932 KB |
Output is correct |
6 |
Correct |
8 ms |
14784 KB |
Output is correct |
7 |
Correct |
10 ms |
14804 KB |
Output is correct |
8 |
Correct |
8 ms |
14804 KB |
Output is correct |
9 |
Correct |
8 ms |
14932 KB |
Output is correct |
10 |
Correct |
8 ms |
14804 KB |
Output is correct |
11 |
Correct |
8 ms |
14828 KB |
Output is correct |
12 |
Correct |
8 ms |
14804 KB |
Output is correct |
13 |
Correct |
8 ms |
14832 KB |
Output is correct |
14 |
Correct |
9 ms |
14924 KB |
Output is correct |
15 |
Correct |
7 ms |
14420 KB |
Output is correct |
16 |
Correct |
7 ms |
14420 KB |
Output is correct |
17 |
Correct |
155 ms |
56320 KB |
Output is correct |
18 |
Correct |
163 ms |
59560 KB |
Output is correct |
19 |
Correct |
190 ms |
59140 KB |
Output is correct |
20 |
Correct |
203 ms |
60632 KB |
Output is correct |
21 |
Correct |
194 ms |
60620 KB |
Output is correct |
22 |
Correct |
226 ms |
64436 KB |
Output is correct |
23 |
Correct |
158 ms |
61912 KB |
Output is correct |
24 |
Correct |
179 ms |
60396 KB |
Output is correct |
25 |
Correct |
220 ms |
60292 KB |
Output is correct |
26 |
Correct |
259 ms |
61672 KB |
Output is correct |
27 |
Correct |
136 ms |
58176 KB |
Output is correct |
28 |
Correct |
145 ms |
58368 KB |
Output is correct |
29 |
Correct |
150 ms |
59704 KB |
Output is correct |
30 |
Correct |
113 ms |
58684 KB |
Output is correct |
31 |
Correct |
7 ms |
14420 KB |
Output is correct |
32 |
Correct |
231 ms |
55004 KB |
Output is correct |
33 |
Correct |
232 ms |
59680 KB |
Output is correct |
34 |
Correct |
170 ms |
59764 KB |
Output is correct |
35 |
Correct |
138 ms |
58200 KB |
Output is correct |
36 |
Correct |
222 ms |
59724 KB |
Output is correct |
37 |
Correct |
176 ms |
59752 KB |
Output is correct |
38 |
Correct |
170 ms |
59780 KB |
Output is correct |
39 |
Correct |
107 ms |
58612 KB |
Output is correct |
40 |
Correct |
156 ms |
59772 KB |
Output is correct |
41 |
Correct |
196 ms |
58452 KB |
Output is correct |
42 |
Correct |
7 ms |
14420 KB |
Output is correct |
43 |
Correct |
283 ms |
56412 KB |
Output is correct |
44 |
Correct |
278 ms |
60584 KB |
Output is correct |
45 |
Correct |
321 ms |
60944 KB |
Output is correct |
46 |
Correct |
236 ms |
60824 KB |
Output is correct |
47 |
Correct |
239 ms |
60984 KB |
Output is correct |
48 |
Correct |
189 ms |
61240 KB |
Output is correct |
49 |
Correct |
144 ms |
66380 KB |
Output is correct |
50 |
Correct |
185 ms |
50192 KB |
Output is correct |
51 |
Correct |
257 ms |
59416 KB |
Output is correct |
52 |
Correct |
188 ms |
58464 KB |
Output is correct |
53 |
Correct |
7 ms |
14420 KB |
Output is correct |
54 |
Correct |
7 ms |
14392 KB |
Output is correct |
55 |
Correct |
6 ms |
14432 KB |
Output is correct |
56 |
Correct |
8 ms |
14816 KB |
Output is correct |
57 |
Correct |
8 ms |
14816 KB |
Output is correct |
58 |
Correct |
9 ms |
14804 KB |
Output is correct |
59 |
Correct |
8 ms |
14824 KB |
Output is correct |
60 |
Correct |
9 ms |
14824 KB |
Output is correct |
61 |
Correct |
10 ms |
14956 KB |
Output is correct |
62 |
Correct |
8 ms |
14828 KB |
Output is correct |
63 |
Correct |
8 ms |
14804 KB |
Output is correct |
64 |
Correct |
7 ms |
14824 KB |
Output is correct |
65 |
Correct |
8 ms |
14844 KB |
Output is correct |
66 |
Correct |
9 ms |
14780 KB |
Output is correct |
67 |
Correct |
161 ms |
60672 KB |
Output is correct |
68 |
Correct |
158 ms |
59584 KB |
Output is correct |
69 |
Correct |
219 ms |
59176 KB |
Output is correct |
70 |
Correct |
193 ms |
60628 KB |
Output is correct |
71 |
Correct |
198 ms |
60712 KB |
Output is correct |
72 |
Correct |
245 ms |
64576 KB |
Output is correct |
73 |
Correct |
188 ms |
61936 KB |
Output is correct |
74 |
Correct |
185 ms |
60436 KB |
Output is correct |
75 |
Correct |
204 ms |
60272 KB |
Output is correct |
76 |
Correct |
212 ms |
61672 KB |
Output is correct |
77 |
Correct |
143 ms |
58188 KB |
Output is correct |
78 |
Correct |
148 ms |
58332 KB |
Output is correct |
79 |
Correct |
143 ms |
59680 KB |
Output is correct |
80 |
Correct |
104 ms |
58616 KB |
Output is correct |
81 |
Correct |
253 ms |
59504 KB |
Output is correct |
82 |
Correct |
230 ms |
59752 KB |
Output is correct |
83 |
Correct |
154 ms |
59712 KB |
Output is correct |
84 |
Correct |
139 ms |
58136 KB |
Output is correct |
85 |
Correct |
224 ms |
59716 KB |
Output is correct |
86 |
Correct |
162 ms |
59752 KB |
Output is correct |
87 |
Correct |
160 ms |
59728 KB |
Output is correct |
88 |
Correct |
144 ms |
59632 KB |
Output is correct |
89 |
Correct |
204 ms |
58388 KB |
Output is correct |
90 |
Correct |
288 ms |
60752 KB |
Output is correct |
91 |
Correct |
288 ms |
60604 KB |
Output is correct |
92 |
Correct |
299 ms |
60884 KB |
Output is correct |
93 |
Correct |
249 ms |
60756 KB |
Output is correct |
94 |
Correct |
241 ms |
60904 KB |
Output is correct |
95 |
Correct |
192 ms |
61248 KB |
Output is correct |
96 |
Correct |
145 ms |
66380 KB |
Output is correct |
97 |
Correct |
181 ms |
50228 KB |
Output is correct |
98 |
Correct |
221 ms |
59340 KB |
Output is correct |
99 |
Correct |
174 ms |
58352 KB |
Output is correct |
100 |
Correct |
94 ms |
33728 KB |
Output is correct |
101 |
Correct |
296 ms |
60860 KB |
Output is correct |
102 |
Correct |
231 ms |
61456 KB |
Output is correct |
103 |
Correct |
283 ms |
61964 KB |
Output is correct |
104 |
Correct |
317 ms |
61576 KB |
Output is correct |