#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/extc++.h>
#define all(v) v.begin(), v.end()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll n, m, a[200020];
vector<ll> adj[200020], can[200020];
bool visited[200020];
vector<tuple<ll,ll,ll>> edges;
struct disjoin_set{
ll papa[200020], sum[200020], sz[200020];
void init() {
memset(papa,-1,sizeof(papa));
for(ll i=1;i<=n;i++) sum[i]=a[i], sz[i]=1, papa[i]=-1, can[i].emplace_back(i);
}
ll Find(ll u) {
if(papa[u]==-1) return u;
return papa[u]=Find(papa[u]);
}
bool Union(ll u,ll v) {
u=Find(u), v=Find(v);
if(u==v) return false;
if(sz[u]<sz[v]) swap(u,v);
papa[v]=u;
sz[u]+=sz[v];
sum[u]+=sum[v];
for(auto x: can[v]) can[u].emplace_back(x);
return true;
}
} djs;
void solve() {
cin>>n>>m;
for(ll i=1;i<=n;i++) cin>>a[i];
while(m --> 0) {
ll u, v; cin>>u>>v;
if(a[u]<a[v]) swap(u,v);
edges.push_back({a[u],u,v});
}
sort(all(edges));
djs.init();
for(auto [_, u, v]: edges) {
if(djs.sum[djs.Find(v)]<a[u]) can[djs.Find(v)].clear();
djs.Union(u,v);
}
for(ll x: can[djs.Find(1)]) visited[x]=1;
for(ll i=1;i<=n;i++) cout<<visited[i];
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int tc=1; //cin>>tc;
while(tc--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
4 ms |
14768 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
5 ms |
14940 KB |
Output is correct |
5 |
Correct |
5 ms |
15196 KB |
Output is correct |
6 |
Correct |
4 ms |
14940 KB |
Output is correct |
7 |
Correct |
4 ms |
14936 KB |
Output is correct |
8 |
Correct |
4 ms |
14936 KB |
Output is correct |
9 |
Correct |
4 ms |
15192 KB |
Output is correct |
10 |
Correct |
4 ms |
15196 KB |
Output is correct |
11 |
Correct |
4 ms |
15196 KB |
Output is correct |
12 |
Correct |
4 ms |
15220 KB |
Output is correct |
13 |
Correct |
5 ms |
14936 KB |
Output is correct |
14 |
Correct |
5 ms |
15192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
4 ms |
14940 KB |
Output is correct |
3 |
Correct |
87 ms |
30468 KB |
Output is correct |
4 |
Correct |
75 ms |
31132 KB |
Output is correct |
5 |
Correct |
92 ms |
34832 KB |
Output is correct |
6 |
Correct |
95 ms |
38340 KB |
Output is correct |
7 |
Correct |
93 ms |
38540 KB |
Output is correct |
8 |
Correct |
89 ms |
35252 KB |
Output is correct |
9 |
Correct |
89 ms |
42940 KB |
Output is correct |
10 |
Correct |
75 ms |
31372 KB |
Output is correct |
11 |
Correct |
76 ms |
34488 KB |
Output is correct |
12 |
Correct |
95 ms |
33940 KB |
Output is correct |
13 |
Correct |
75 ms |
35004 KB |
Output is correct |
14 |
Correct |
75 ms |
33976 KB |
Output is correct |
15 |
Correct |
79 ms |
36020 KB |
Output is correct |
16 |
Correct |
60 ms |
35768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
103 ms |
36444 KB |
Output is correct |
3 |
Correct |
111 ms |
40372 KB |
Output is correct |
4 |
Correct |
82 ms |
36528 KB |
Output is correct |
5 |
Correct |
81 ms |
34228 KB |
Output is correct |
6 |
Correct |
102 ms |
41400 KB |
Output is correct |
7 |
Correct |
83 ms |
36104 KB |
Output is correct |
8 |
Correct |
81 ms |
35520 KB |
Output is correct |
9 |
Correct |
60 ms |
35692 KB |
Output is correct |
10 |
Correct |
82 ms |
33208 KB |
Output is correct |
11 |
Correct |
91 ms |
35104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
102 ms |
31144 KB |
Output is correct |
3 |
Correct |
101 ms |
36536 KB |
Output is correct |
4 |
Correct |
107 ms |
39344 KB |
Output is correct |
5 |
Correct |
113 ms |
41168 KB |
Output is correct |
6 |
Correct |
103 ms |
38996 KB |
Output is correct |
7 |
Correct |
82 ms |
35732 KB |
Output is correct |
8 |
Correct |
69 ms |
32436 KB |
Output is correct |
9 |
Correct |
72 ms |
28600 KB |
Output is correct |
10 |
Correct |
109 ms |
42416 KB |
Output is correct |
11 |
Correct |
85 ms |
33464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
4 ms |
14768 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
5 ms |
14940 KB |
Output is correct |
5 |
Correct |
5 ms |
15196 KB |
Output is correct |
6 |
Correct |
4 ms |
14940 KB |
Output is correct |
7 |
Correct |
4 ms |
14936 KB |
Output is correct |
8 |
Correct |
4 ms |
14936 KB |
Output is correct |
9 |
Correct |
4 ms |
15192 KB |
Output is correct |
10 |
Correct |
4 ms |
15196 KB |
Output is correct |
11 |
Correct |
4 ms |
15196 KB |
Output is correct |
12 |
Correct |
4 ms |
15220 KB |
Output is correct |
13 |
Correct |
5 ms |
14936 KB |
Output is correct |
14 |
Correct |
5 ms |
15192 KB |
Output is correct |
15 |
Correct |
4 ms |
14936 KB |
Output is correct |
16 |
Correct |
4 ms |
14940 KB |
Output is correct |
17 |
Correct |
87 ms |
30468 KB |
Output is correct |
18 |
Correct |
75 ms |
31132 KB |
Output is correct |
19 |
Correct |
92 ms |
34832 KB |
Output is correct |
20 |
Correct |
95 ms |
38340 KB |
Output is correct |
21 |
Correct |
93 ms |
38540 KB |
Output is correct |
22 |
Correct |
89 ms |
35252 KB |
Output is correct |
23 |
Correct |
89 ms |
42940 KB |
Output is correct |
24 |
Correct |
75 ms |
31372 KB |
Output is correct |
25 |
Correct |
76 ms |
34488 KB |
Output is correct |
26 |
Correct |
95 ms |
33940 KB |
Output is correct |
27 |
Correct |
75 ms |
35004 KB |
Output is correct |
28 |
Correct |
75 ms |
33976 KB |
Output is correct |
29 |
Correct |
79 ms |
36020 KB |
Output is correct |
30 |
Correct |
60 ms |
35768 KB |
Output is correct |
31 |
Correct |
3 ms |
14940 KB |
Output is correct |
32 |
Correct |
103 ms |
36444 KB |
Output is correct |
33 |
Correct |
111 ms |
40372 KB |
Output is correct |
34 |
Correct |
82 ms |
36528 KB |
Output is correct |
35 |
Correct |
81 ms |
34228 KB |
Output is correct |
36 |
Correct |
102 ms |
41400 KB |
Output is correct |
37 |
Correct |
83 ms |
36104 KB |
Output is correct |
38 |
Correct |
81 ms |
35520 KB |
Output is correct |
39 |
Correct |
60 ms |
35692 KB |
Output is correct |
40 |
Correct |
82 ms |
33208 KB |
Output is correct |
41 |
Correct |
91 ms |
35104 KB |
Output is correct |
42 |
Correct |
3 ms |
14940 KB |
Output is correct |
43 |
Correct |
102 ms |
31144 KB |
Output is correct |
44 |
Correct |
101 ms |
36536 KB |
Output is correct |
45 |
Correct |
107 ms |
39344 KB |
Output is correct |
46 |
Correct |
113 ms |
41168 KB |
Output is correct |
47 |
Correct |
103 ms |
38996 KB |
Output is correct |
48 |
Correct |
82 ms |
35732 KB |
Output is correct |
49 |
Correct |
69 ms |
32436 KB |
Output is correct |
50 |
Correct |
72 ms |
28600 KB |
Output is correct |
51 |
Correct |
109 ms |
42416 KB |
Output is correct |
52 |
Correct |
85 ms |
33464 KB |
Output is correct |
53 |
Correct |
4 ms |
14936 KB |
Output is correct |
54 |
Correct |
3 ms |
14940 KB |
Output is correct |
55 |
Correct |
4 ms |
14936 KB |
Output is correct |
56 |
Correct |
4 ms |
15128 KB |
Output is correct |
57 |
Correct |
5 ms |
15192 KB |
Output is correct |
58 |
Correct |
4 ms |
14940 KB |
Output is correct |
59 |
Correct |
4 ms |
14940 KB |
Output is correct |
60 |
Correct |
4 ms |
14940 KB |
Output is correct |
61 |
Correct |
4 ms |
15032 KB |
Output is correct |
62 |
Correct |
5 ms |
15196 KB |
Output is correct |
63 |
Correct |
4 ms |
15196 KB |
Output is correct |
64 |
Correct |
4 ms |
15196 KB |
Output is correct |
65 |
Correct |
4 ms |
15164 KB |
Output is correct |
66 |
Correct |
4 ms |
14940 KB |
Output is correct |
67 |
Correct |
89 ms |
35472 KB |
Output is correct |
68 |
Correct |
76 ms |
34480 KB |
Output is correct |
69 |
Correct |
89 ms |
39088 KB |
Output is correct |
70 |
Correct |
99 ms |
39348 KB |
Output is correct |
71 |
Correct |
107 ms |
39208 KB |
Output is correct |
72 |
Correct |
95 ms |
36272 KB |
Output is correct |
73 |
Correct |
91 ms |
43296 KB |
Output is correct |
74 |
Correct |
74 ms |
30944 KB |
Output is correct |
75 |
Correct |
80 ms |
35612 KB |
Output is correct |
76 |
Correct |
90 ms |
34228 KB |
Output is correct |
77 |
Correct |
75 ms |
34480 KB |
Output is correct |
78 |
Correct |
83 ms |
35204 KB |
Output is correct |
79 |
Correct |
81 ms |
36052 KB |
Output is correct |
80 |
Correct |
63 ms |
35776 KB |
Output is correct |
81 |
Correct |
117 ms |
41140 KB |
Output is correct |
82 |
Correct |
107 ms |
40368 KB |
Output is correct |
83 |
Correct |
83 ms |
37300 KB |
Output is correct |
84 |
Correct |
76 ms |
34064 KB |
Output is correct |
85 |
Correct |
115 ms |
40504 KB |
Output is correct |
86 |
Correct |
81 ms |
36728 KB |
Output is correct |
87 |
Correct |
79 ms |
35392 KB |
Output is correct |
88 |
Correct |
88 ms |
34236 KB |
Output is correct |
89 |
Correct |
87 ms |
34480 KB |
Output is correct |
90 |
Correct |
105 ms |
36672 KB |
Output is correct |
91 |
Correct |
105 ms |
36684 KB |
Output is correct |
92 |
Correct |
109 ms |
38836 KB |
Output is correct |
93 |
Correct |
122 ms |
41396 KB |
Output is correct |
94 |
Correct |
115 ms |
38820 KB |
Output is correct |
95 |
Correct |
83 ms |
35220 KB |
Output is correct |
96 |
Correct |
70 ms |
33720 KB |
Output is correct |
97 |
Correct |
75 ms |
28084 KB |
Output is correct |
98 |
Correct |
105 ms |
41196 KB |
Output is correct |
99 |
Correct |
94 ms |
33812 KB |
Output is correct |
100 |
Correct |
50 ms |
21688 KB |
Output is correct |
101 |
Correct |
122 ms |
37912 KB |
Output is correct |
102 |
Correct |
91 ms |
33972 KB |
Output is correct |
103 |
Correct |
88 ms |
32944 KB |
Output is correct |
104 |
Correct |
111 ms |
34744 KB |
Output is correct |