#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/* DEFINES */
#define S second
#define F first
#define ll long long
#define ull unsigned long long
#define ld long double
#define npos ULLONG_MAX
#define INF LLONG_MAX
#define vv(a) vector<a>
#define ss(a) set<a>
#define pp(a, b) pair<a, b>
#define mm(a, b) map<a, b>
#define qq(a) queue<a>
#define pq(a) priority_queue<a>
#define ump(a, b) unordered_map<a, b>
#define ANDROID \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define allc(a) begin(a), end(a)
#define all(a) a, a + sizeof(a) / sizeof(a[0])
#define elif else if
#define endl "\n"
#define pb push_back
#define ins insert
#define logi __lg
#define sqrt sqrtl
#define mpr make_pair
using namespace std;
using namespace __cxx11;
using namespace __gnu_pbds;
typedef char chr;
typedef basic_string<chr> str;
template <typename T, typename key = less<T>>
using ordered_set = tree<T, null_type, key, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 2e5 + 5;
ll b[N];
struct Dsu
{
ll n, ans;
vv(ll) dsu, sum;
vv(vv(ll)) s;
Dsu(ll sz = 1)
{
n = sz;
ans = n;
dsu.resize(n + 1, 0);
sum.resize(n + 1, 0);
s.resize(n + 1);
init();
}
void init()
{
for (ll i = 1; i <= n; i++)
dsu[i] = -1, s[i] = {i};
}
bool Union(ll x, ll y)
{
x = repr(x), y = repr(y);
if (x == y)
return false;
if (dsu[x] < dsu[y])
swap(x, y);
ans--;
for (ll i : s[x])
s[y].pb(i);
s[x].clear();
dsu[y] += dsu[x];
sum[y] += sum[x];
dsu[x] = y;
return true;
}
ll repr(ll x)
{
if (dsu[x] < 0)
return x;
return dsu[x] = repr(dsu[x]);
}
ll query()
{
return ans;
}
ll size(ll x)
{
return -dsu[repr(x)];
}
};
void solve()
{
ll n, m;
cin >> n >> m;
pp(ll, ll) a[n + 1];
vv(ll) g[n + 1];
for (ll i = 1; i <= n; i++)
cin >> a[i].F, a[i].S = i, b[i] = a[i].F;
Dsu dsu(n);
for (ll i = 1; i <= n; i++)
dsu.sum[i] = b[i];
while (m--)
{
ll a, b;
cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
}
sort(a + 1, a + n + 1);
ll ans[n + 1];
for (ll i = 1; i <= n; i++)
ans[i] = 1;
for (ll _ = 1; _ <= n; _++)
for (ll i : {a[_].S})
for (ll j : g[i])
if (b[j] <= b[i])
{
ll rprj = dsu.repr(j), rpri = dsu.repr(i);
if (dsu.sum[rprj] < b[i])
{
for (ll k : dsu.s[rprj])
ans[k] = 0;
dsu.s[rprj].clear();
}
dsu.Union(rprj, rpri);
}
for (ll i = 1; i <= n; i++)
cout << ans[i];
cout << endl;
}
/*
*/
int main()
{
ANDROID
// precomp();
ll t = 1;
// cin >> t;
for (ll i = 1; i <= t; i++)
// cout << "Case #" << i << ": ",
solve();
cerr << "\nTime elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
656 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
140 ms |
37996 KB |
Output is correct |
4 |
Correct |
123 ms |
36548 KB |
Output is correct |
5 |
Correct |
187 ms |
39524 KB |
Output is correct |
6 |
Correct |
171 ms |
41084 KB |
Output is correct |
7 |
Correct |
183 ms |
41096 KB |
Output is correct |
8 |
Correct |
159 ms |
37304 KB |
Output is correct |
9 |
Correct |
137 ms |
45224 KB |
Output is correct |
10 |
Correct |
130 ms |
35520 KB |
Output is correct |
11 |
Correct |
133 ms |
38340 KB |
Output is correct |
12 |
Correct |
178 ms |
36868 KB |
Output is correct |
13 |
Correct |
118 ms |
35528 KB |
Output is correct |
14 |
Correct |
124 ms |
35560 KB |
Output is correct |
15 |
Correct |
116 ms |
36416 KB |
Output is correct |
16 |
Correct |
85 ms |
35524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
196 ms |
41404 KB |
Output is correct |
3 |
Correct |
205 ms |
41792 KB |
Output is correct |
4 |
Correct |
134 ms |
36296 KB |
Output is correct |
5 |
Correct |
113 ms |
35776 KB |
Output is correct |
6 |
Correct |
201 ms |
41672 KB |
Output is correct |
7 |
Correct |
144 ms |
36292 KB |
Output is correct |
8 |
Correct |
151 ms |
36404 KB |
Output is correct |
9 |
Correct |
81 ms |
35524 KB |
Output is correct |
10 |
Correct |
119 ms |
34816 KB |
Output is correct |
11 |
Correct |
138 ms |
36140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
213 ms |
38868 KB |
Output is correct |
3 |
Correct |
211 ms |
39128 KB |
Output is correct |
4 |
Correct |
233 ms |
41652 KB |
Output is correct |
5 |
Correct |
212 ms |
43080 KB |
Output is correct |
6 |
Correct |
184 ms |
38936 KB |
Output is correct |
7 |
Correct |
121 ms |
38848 KB |
Output is correct |
8 |
Correct |
81 ms |
36104 KB |
Output is correct |
9 |
Correct |
95 ms |
21524 KB |
Output is correct |
10 |
Correct |
190 ms |
43956 KB |
Output is correct |
11 |
Correct |
143 ms |
36316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
656 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
140 ms |
37996 KB |
Output is correct |
18 |
Correct |
123 ms |
36548 KB |
Output is correct |
19 |
Correct |
187 ms |
39524 KB |
Output is correct |
20 |
Correct |
171 ms |
41084 KB |
Output is correct |
21 |
Correct |
183 ms |
41096 KB |
Output is correct |
22 |
Correct |
159 ms |
37304 KB |
Output is correct |
23 |
Correct |
137 ms |
45224 KB |
Output is correct |
24 |
Correct |
130 ms |
35520 KB |
Output is correct |
25 |
Correct |
133 ms |
38340 KB |
Output is correct |
26 |
Correct |
178 ms |
36868 KB |
Output is correct |
27 |
Correct |
118 ms |
35528 KB |
Output is correct |
28 |
Correct |
124 ms |
35560 KB |
Output is correct |
29 |
Correct |
116 ms |
36416 KB |
Output is correct |
30 |
Correct |
85 ms |
35524 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
196 ms |
41404 KB |
Output is correct |
33 |
Correct |
205 ms |
41792 KB |
Output is correct |
34 |
Correct |
134 ms |
36296 KB |
Output is correct |
35 |
Correct |
113 ms |
35776 KB |
Output is correct |
36 |
Correct |
201 ms |
41672 KB |
Output is correct |
37 |
Correct |
144 ms |
36292 KB |
Output is correct |
38 |
Correct |
151 ms |
36404 KB |
Output is correct |
39 |
Correct |
81 ms |
35524 KB |
Output is correct |
40 |
Correct |
119 ms |
34816 KB |
Output is correct |
41 |
Correct |
138 ms |
36140 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
213 ms |
38868 KB |
Output is correct |
44 |
Correct |
211 ms |
39128 KB |
Output is correct |
45 |
Correct |
233 ms |
41652 KB |
Output is correct |
46 |
Correct |
212 ms |
43080 KB |
Output is correct |
47 |
Correct |
184 ms |
38936 KB |
Output is correct |
48 |
Correct |
121 ms |
38848 KB |
Output is correct |
49 |
Correct |
81 ms |
36104 KB |
Output is correct |
50 |
Correct |
95 ms |
21524 KB |
Output is correct |
51 |
Correct |
190 ms |
43956 KB |
Output is correct |
52 |
Correct |
143 ms |
36316 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
344 KB |
Output is correct |
56 |
Correct |
2 ms |
600 KB |
Output is correct |
57 |
Correct |
2 ms |
856 KB |
Output is correct |
58 |
Correct |
1 ms |
600 KB |
Output is correct |
59 |
Correct |
1 ms |
600 KB |
Output is correct |
60 |
Correct |
1 ms |
600 KB |
Output is correct |
61 |
Correct |
1 ms |
600 KB |
Output is correct |
62 |
Correct |
2 ms |
708 KB |
Output is correct |
63 |
Correct |
1 ms |
856 KB |
Output is correct |
64 |
Correct |
1 ms |
856 KB |
Output is correct |
65 |
Correct |
1 ms |
600 KB |
Output is correct |
66 |
Correct |
1 ms |
856 KB |
Output is correct |
67 |
Correct |
123 ms |
37816 KB |
Output is correct |
68 |
Correct |
124 ms |
36548 KB |
Output is correct |
69 |
Correct |
179 ms |
39764 KB |
Output is correct |
70 |
Correct |
165 ms |
40904 KB |
Output is correct |
71 |
Correct |
162 ms |
41024 KB |
Output is correct |
72 |
Correct |
159 ms |
37316 KB |
Output is correct |
73 |
Correct |
138 ms |
44984 KB |
Output is correct |
74 |
Correct |
124 ms |
35520 KB |
Output is correct |
75 |
Correct |
130 ms |
38336 KB |
Output is correct |
76 |
Correct |
173 ms |
37268 KB |
Output is correct |
77 |
Correct |
110 ms |
35524 KB |
Output is correct |
78 |
Correct |
136 ms |
35564 KB |
Output is correct |
79 |
Correct |
116 ms |
36448 KB |
Output is correct |
80 |
Correct |
85 ms |
35524 KB |
Output is correct |
81 |
Correct |
205 ms |
41392 KB |
Output is correct |
82 |
Correct |
201 ms |
41792 KB |
Output is correct |
83 |
Correct |
135 ms |
36420 KB |
Output is correct |
84 |
Correct |
115 ms |
35776 KB |
Output is correct |
85 |
Correct |
188 ms |
41672 KB |
Output is correct |
86 |
Correct |
141 ms |
36292 KB |
Output is correct |
87 |
Correct |
130 ms |
36292 KB |
Output is correct |
88 |
Correct |
136 ms |
35012 KB |
Output is correct |
89 |
Correct |
147 ms |
36124 KB |
Output is correct |
90 |
Correct |
222 ms |
38404 KB |
Output is correct |
91 |
Correct |
213 ms |
39104 KB |
Output is correct |
92 |
Correct |
221 ms |
41492 KB |
Output is correct |
93 |
Correct |
222 ms |
43084 KB |
Output is correct |
94 |
Correct |
184 ms |
38844 KB |
Output is correct |
95 |
Correct |
140 ms |
39108 KB |
Output is correct |
96 |
Correct |
81 ms |
36108 KB |
Output is correct |
97 |
Correct |
93 ms |
21444 KB |
Output is correct |
98 |
Correct |
176 ms |
44076 KB |
Output is correct |
99 |
Correct |
138 ms |
36120 KB |
Output is correct |
100 |
Correct |
38 ms |
6736 KB |
Output is correct |
101 |
Correct |
221 ms |
39656 KB |
Output is correct |
102 |
Correct |
160 ms |
32656 KB |
Output is correct |
103 |
Correct |
175 ms |
32232 KB |
Output is correct |
104 |
Correct |
213 ms |
37320 KB |
Output is correct |