#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
typedef long long llong;
const int MAXN = 200000 + 10;
const int INF = 1e9 + 10;
int n, m;
int a[MAXN], s[MAXN], inS[MAXN];
std::vector < int > g[MAXN];
std::vector < int > alive[MAXN];
struct DSUelement
{
int par;
int sum;
} c[MAXN];
int find(int x)
{
if (c[x].par == x) return x;
return c[x].par = find(c[x].par);
}
void connect(int x, int y)
{
x = find(x);
y = find(y);
if (alive[x].size() > alive[y].size()) std::swap(x, y);
c[x].par = y;
c[y].sum += c[x].sum;
c[y].sum = std::min(c[y].sum, INF);
// alive[y].reserve(alive[x].size() + alive[y].size());
for (int i : alive[x])
{
alive[y].push_back(i);
}
}
bool areConnected(int x, int y)
{
return find(x) == find(y);
}
char ans[MAXN];
void solve()
{
std::iota(s+1, s+n+1, 1);
std::sort(s+1, s+n+1, [&](int x, int y)
{
return a[x] < a[y];
});
for (int i = 1 ; i <= n ; ++i)
{
inS[s[i]] = i;
c[i].par = i;
c[i].sum = a[i];
alive[i].push_back(i);
}
for (int i = 1 ; i <= n ; ++i)
{
int x = s[i];
for (const int &j : g[x])
{
if (inS[j] > i || areConnected(x, j)) continue;
int par = find(j);
if (c[par].sum < a[x])
{
alive[par].clear();
}
connect(x, j);
}
}
int findPar = find(1);
std::fill(ans, ans+n, '0');
for (int i : alive[findPar])
{
ans[i-1] = '1';
}
ans[n] = '\0';
std::cout << ans << '\n';
}
void read()
{
std::cin >> n >> m;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
for (int i = 1 ; i <= m ; ++i)
{
int x, y;
std::cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
}
void fastIO()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIO();
read();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9732 KB |
Output is correct |
3 |
Correct |
6 ms |
9668 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
8 ms |
9900 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9808 KB |
Output is correct |
9 |
Correct |
6 ms |
9812 KB |
Output is correct |
10 |
Correct |
7 ms |
9940 KB |
Output is correct |
11 |
Correct |
8 ms |
9820 KB |
Output is correct |
12 |
Correct |
10 ms |
9876 KB |
Output is correct |
13 |
Correct |
6 ms |
9940 KB |
Output is correct |
14 |
Correct |
6 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
175 ms |
27368 KB |
Output is correct |
4 |
Correct |
155 ms |
30592 KB |
Output is correct |
5 |
Correct |
159 ms |
28996 KB |
Output is correct |
6 |
Correct |
177 ms |
29664 KB |
Output is correct |
7 |
Correct |
190 ms |
29756 KB |
Output is correct |
8 |
Correct |
172 ms |
28864 KB |
Output is correct |
9 |
Correct |
152 ms |
30816 KB |
Output is correct |
10 |
Correct |
118 ms |
27560 KB |
Output is correct |
11 |
Correct |
131 ms |
28688 KB |
Output is correct |
12 |
Correct |
185 ms |
28328 KB |
Output is correct |
13 |
Correct |
150 ms |
31144 KB |
Output is correct |
14 |
Correct |
192 ms |
30860 KB |
Output is correct |
15 |
Correct |
132 ms |
27720 KB |
Output is correct |
16 |
Correct |
106 ms |
27480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
215 ms |
30156 KB |
Output is correct |
3 |
Correct |
193 ms |
30196 KB |
Output is correct |
4 |
Correct |
140 ms |
30988 KB |
Output is correct |
5 |
Correct |
147 ms |
30816 KB |
Output is correct |
6 |
Correct |
217 ms |
30192 KB |
Output is correct |
7 |
Correct |
141 ms |
27384 KB |
Output is correct |
8 |
Correct |
185 ms |
27696 KB |
Output is correct |
9 |
Correct |
101 ms |
27380 KB |
Output is correct |
10 |
Correct |
132 ms |
28568 KB |
Output is correct |
11 |
Correct |
151 ms |
30080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
185 ms |
27960 KB |
Output is correct |
3 |
Correct |
182 ms |
28536 KB |
Output is correct |
4 |
Correct |
181 ms |
29380 KB |
Output is correct |
5 |
Correct |
232 ms |
30268 KB |
Output is correct |
6 |
Correct |
161 ms |
27968 KB |
Output is correct |
7 |
Correct |
145 ms |
28616 KB |
Output is correct |
8 |
Correct |
93 ms |
29412 KB |
Output is correct |
9 |
Correct |
124 ms |
19872 KB |
Output is correct |
10 |
Correct |
187 ms |
31240 KB |
Output is correct |
11 |
Correct |
145 ms |
30148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9732 KB |
Output is correct |
3 |
Correct |
6 ms |
9668 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
8 ms |
9900 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9808 KB |
Output is correct |
9 |
Correct |
6 ms |
9812 KB |
Output is correct |
10 |
Correct |
7 ms |
9940 KB |
Output is correct |
11 |
Correct |
8 ms |
9820 KB |
Output is correct |
12 |
Correct |
10 ms |
9876 KB |
Output is correct |
13 |
Correct |
6 ms |
9940 KB |
Output is correct |
14 |
Correct |
6 ms |
9812 KB |
Output is correct |
15 |
Correct |
7 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
175 ms |
27368 KB |
Output is correct |
18 |
Correct |
155 ms |
30592 KB |
Output is correct |
19 |
Correct |
159 ms |
28996 KB |
Output is correct |
20 |
Correct |
177 ms |
29664 KB |
Output is correct |
21 |
Correct |
190 ms |
29756 KB |
Output is correct |
22 |
Correct |
172 ms |
28864 KB |
Output is correct |
23 |
Correct |
152 ms |
30816 KB |
Output is correct |
24 |
Correct |
118 ms |
27560 KB |
Output is correct |
25 |
Correct |
131 ms |
28688 KB |
Output is correct |
26 |
Correct |
185 ms |
28328 KB |
Output is correct |
27 |
Correct |
150 ms |
31144 KB |
Output is correct |
28 |
Correct |
192 ms |
30860 KB |
Output is correct |
29 |
Correct |
132 ms |
27720 KB |
Output is correct |
30 |
Correct |
106 ms |
27480 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
215 ms |
30156 KB |
Output is correct |
33 |
Correct |
193 ms |
30196 KB |
Output is correct |
34 |
Correct |
140 ms |
30988 KB |
Output is correct |
35 |
Correct |
147 ms |
30816 KB |
Output is correct |
36 |
Correct |
217 ms |
30192 KB |
Output is correct |
37 |
Correct |
141 ms |
27384 KB |
Output is correct |
38 |
Correct |
185 ms |
27696 KB |
Output is correct |
39 |
Correct |
101 ms |
27380 KB |
Output is correct |
40 |
Correct |
132 ms |
28568 KB |
Output is correct |
41 |
Correct |
151 ms |
30080 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
185 ms |
27960 KB |
Output is correct |
44 |
Correct |
182 ms |
28536 KB |
Output is correct |
45 |
Correct |
181 ms |
29380 KB |
Output is correct |
46 |
Correct |
232 ms |
30268 KB |
Output is correct |
47 |
Correct |
161 ms |
27968 KB |
Output is correct |
48 |
Correct |
145 ms |
28616 KB |
Output is correct |
49 |
Correct |
93 ms |
29412 KB |
Output is correct |
50 |
Correct |
124 ms |
19872 KB |
Output is correct |
51 |
Correct |
187 ms |
31240 KB |
Output is correct |
52 |
Correct |
145 ms |
30148 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
5 ms |
9684 KB |
Output is correct |
55 |
Correct |
5 ms |
9708 KB |
Output is correct |
56 |
Correct |
6 ms |
9876 KB |
Output is correct |
57 |
Correct |
6 ms |
9876 KB |
Output is correct |
58 |
Correct |
6 ms |
9812 KB |
Output is correct |
59 |
Correct |
7 ms |
9812 KB |
Output is correct |
60 |
Correct |
6 ms |
9796 KB |
Output is correct |
61 |
Correct |
7 ms |
9940 KB |
Output is correct |
62 |
Correct |
7 ms |
9940 KB |
Output is correct |
63 |
Correct |
8 ms |
9932 KB |
Output is correct |
64 |
Correct |
6 ms |
9940 KB |
Output is correct |
65 |
Correct |
6 ms |
9880 KB |
Output is correct |
66 |
Correct |
6 ms |
9940 KB |
Output is correct |
67 |
Correct |
123 ms |
27608 KB |
Output is correct |
68 |
Correct |
136 ms |
30600 KB |
Output is correct |
69 |
Correct |
156 ms |
28972 KB |
Output is correct |
70 |
Correct |
154 ms |
29680 KB |
Output is correct |
71 |
Correct |
148 ms |
29552 KB |
Output is correct |
72 |
Correct |
155 ms |
28872 KB |
Output is correct |
73 |
Correct |
143 ms |
30876 KB |
Output is correct |
74 |
Correct |
101 ms |
27432 KB |
Output is correct |
75 |
Correct |
108 ms |
28620 KB |
Output is correct |
76 |
Correct |
163 ms |
28276 KB |
Output is correct |
77 |
Correct |
126 ms |
31056 KB |
Output is correct |
78 |
Correct |
128 ms |
30704 KB |
Output is correct |
79 |
Correct |
141 ms |
27664 KB |
Output is correct |
80 |
Correct |
82 ms |
27472 KB |
Output is correct |
81 |
Correct |
192 ms |
30364 KB |
Output is correct |
82 |
Correct |
193 ms |
30388 KB |
Output is correct |
83 |
Correct |
144 ms |
31172 KB |
Output is correct |
84 |
Correct |
134 ms |
31252 KB |
Output is correct |
85 |
Correct |
177 ms |
30536 KB |
Output is correct |
86 |
Correct |
142 ms |
27648 KB |
Output is correct |
87 |
Correct |
142 ms |
27700 KB |
Output is correct |
88 |
Correct |
144 ms |
28640 KB |
Output is correct |
89 |
Correct |
150 ms |
29976 KB |
Output is correct |
90 |
Correct |
179 ms |
28288 KB |
Output is correct |
91 |
Correct |
176 ms |
28900 KB |
Output is correct |
92 |
Correct |
204 ms |
29636 KB |
Output is correct |
93 |
Correct |
186 ms |
30512 KB |
Output is correct |
94 |
Correct |
164 ms |
28260 KB |
Output is correct |
95 |
Correct |
120 ms |
28700 KB |
Output is correct |
96 |
Correct |
95 ms |
29444 KB |
Output is correct |
97 |
Correct |
99 ms |
19740 KB |
Output is correct |
98 |
Correct |
220 ms |
31268 KB |
Output is correct |
99 |
Correct |
165 ms |
30168 KB |
Output is correct |
100 |
Correct |
42 ms |
12232 KB |
Output is correct |
101 |
Correct |
195 ms |
28916 KB |
Output is correct |
102 |
Correct |
154 ms |
24596 KB |
Output is correct |
103 |
Correct |
184 ms |
24584 KB |
Output is correct |
104 |
Correct |
185 ms |
27604 KB |
Output is correct |