#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;
int n, m, a[200020];
vector<int> adj[200020], can[200020];
bool visited[200020];
vector<tuple<int,int,int>> edges;
struct disjoin_set{
int papa[200020], sz[200020];
ll sum[200020];
void init() {
for(int i=1;i<=n;i++) sum[i]=a[i], sz[i]=1, papa[i]=-1, can[i].emplace_back(i);
}
int Find(int u) {
if(papa[u]==-1) return u;
return papa[u]=Find(papa[u]);
}
bool Union(int u,int 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(int i=1;i<=n;i++) cin>>a[i];
while(m --> 0) {
int 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(int& x: can[djs.Find(1)]) visited[x]=1;
for(int 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 |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12892 KB |
Output is correct |
4 |
Correct |
4 ms |
13148 KB |
Output is correct |
5 |
Correct |
4 ms |
13064 KB |
Output is correct |
6 |
Correct |
4 ms |
13400 KB |
Output is correct |
7 |
Correct |
6 ms |
13148 KB |
Output is correct |
8 |
Correct |
5 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
13148 KB |
Output is correct |
10 |
Correct |
4 ms |
13024 KB |
Output is correct |
11 |
Correct |
4 ms |
13068 KB |
Output is correct |
12 |
Correct |
5 ms |
13148 KB |
Output is correct |
13 |
Correct |
4 ms |
13148 KB |
Output is correct |
14 |
Correct |
4 ms |
13148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12888 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
87 ms |
27064 KB |
Output is correct |
4 |
Correct |
79 ms |
26496 KB |
Output is correct |
5 |
Correct |
104 ms |
28004 KB |
Output is correct |
6 |
Correct |
93 ms |
28604 KB |
Output is correct |
7 |
Correct |
89 ms |
28680 KB |
Output is correct |
8 |
Correct |
89 ms |
26900 KB |
Output is correct |
9 |
Correct |
92 ms |
30136 KB |
Output is correct |
10 |
Correct |
79 ms |
25136 KB |
Output is correct |
11 |
Correct |
81 ms |
26560 KB |
Output is correct |
12 |
Correct |
85 ms |
25700 KB |
Output is correct |
13 |
Correct |
73 ms |
26300 KB |
Output is correct |
14 |
Correct |
73 ms |
26300 KB |
Output is correct |
15 |
Correct |
81 ms |
27080 KB |
Output is correct |
16 |
Correct |
57 ms |
26308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12892 KB |
Output is correct |
2 |
Correct |
113 ms |
29888 KB |
Output is correct |
3 |
Correct |
96 ms |
29312 KB |
Output is correct |
4 |
Correct |
92 ms |
27092 KB |
Output is correct |
5 |
Correct |
72 ms |
26104 KB |
Output is correct |
6 |
Correct |
95 ms |
29340 KB |
Output is correct |
7 |
Correct |
77 ms |
27008 KB |
Output is correct |
8 |
Correct |
77 ms |
27844 KB |
Output is correct |
9 |
Correct |
57 ms |
26568 KB |
Output is correct |
10 |
Correct |
76 ms |
25528 KB |
Output is correct |
11 |
Correct |
102 ms |
26628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
105 ms |
27428 KB |
Output is correct |
3 |
Correct |
99 ms |
27664 KB |
Output is correct |
4 |
Correct |
104 ms |
28540 KB |
Output is correct |
5 |
Correct |
109 ms |
29816 KB |
Output is correct |
6 |
Correct |
96 ms |
28348 KB |
Output is correct |
7 |
Correct |
80 ms |
27068 KB |
Output is correct |
8 |
Correct |
69 ms |
25280 KB |
Output is correct |
9 |
Correct |
67 ms |
21188 KB |
Output is correct |
10 |
Correct |
96 ms |
29780 KB |
Output is correct |
11 |
Correct |
81 ms |
26300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
4 ms |
12892 KB |
Output is correct |
4 |
Correct |
4 ms |
13148 KB |
Output is correct |
5 |
Correct |
4 ms |
13064 KB |
Output is correct |
6 |
Correct |
4 ms |
13400 KB |
Output is correct |
7 |
Correct |
6 ms |
13148 KB |
Output is correct |
8 |
Correct |
5 ms |
12892 KB |
Output is correct |
9 |
Correct |
4 ms |
13148 KB |
Output is correct |
10 |
Correct |
4 ms |
13024 KB |
Output is correct |
11 |
Correct |
4 ms |
13068 KB |
Output is correct |
12 |
Correct |
5 ms |
13148 KB |
Output is correct |
13 |
Correct |
4 ms |
13148 KB |
Output is correct |
14 |
Correct |
4 ms |
13148 KB |
Output is correct |
15 |
Correct |
4 ms |
12888 KB |
Output is correct |
16 |
Correct |
3 ms |
12892 KB |
Output is correct |
17 |
Correct |
87 ms |
27064 KB |
Output is correct |
18 |
Correct |
79 ms |
26496 KB |
Output is correct |
19 |
Correct |
104 ms |
28004 KB |
Output is correct |
20 |
Correct |
93 ms |
28604 KB |
Output is correct |
21 |
Correct |
89 ms |
28680 KB |
Output is correct |
22 |
Correct |
89 ms |
26900 KB |
Output is correct |
23 |
Correct |
92 ms |
30136 KB |
Output is correct |
24 |
Correct |
79 ms |
25136 KB |
Output is correct |
25 |
Correct |
81 ms |
26560 KB |
Output is correct |
26 |
Correct |
85 ms |
25700 KB |
Output is correct |
27 |
Correct |
73 ms |
26300 KB |
Output is correct |
28 |
Correct |
73 ms |
26300 KB |
Output is correct |
29 |
Correct |
81 ms |
27080 KB |
Output is correct |
30 |
Correct |
57 ms |
26308 KB |
Output is correct |
31 |
Correct |
3 ms |
12892 KB |
Output is correct |
32 |
Correct |
113 ms |
29888 KB |
Output is correct |
33 |
Correct |
96 ms |
29312 KB |
Output is correct |
34 |
Correct |
92 ms |
27092 KB |
Output is correct |
35 |
Correct |
72 ms |
26104 KB |
Output is correct |
36 |
Correct |
95 ms |
29340 KB |
Output is correct |
37 |
Correct |
77 ms |
27008 KB |
Output is correct |
38 |
Correct |
77 ms |
27844 KB |
Output is correct |
39 |
Correct |
57 ms |
26568 KB |
Output is correct |
40 |
Correct |
76 ms |
25528 KB |
Output is correct |
41 |
Correct |
102 ms |
26628 KB |
Output is correct |
42 |
Correct |
4 ms |
12892 KB |
Output is correct |
43 |
Correct |
105 ms |
27428 KB |
Output is correct |
44 |
Correct |
99 ms |
27664 KB |
Output is correct |
45 |
Correct |
104 ms |
28540 KB |
Output is correct |
46 |
Correct |
109 ms |
29816 KB |
Output is correct |
47 |
Correct |
96 ms |
28348 KB |
Output is correct |
48 |
Correct |
80 ms |
27068 KB |
Output is correct |
49 |
Correct |
69 ms |
25280 KB |
Output is correct |
50 |
Correct |
67 ms |
21188 KB |
Output is correct |
51 |
Correct |
96 ms |
29780 KB |
Output is correct |
52 |
Correct |
81 ms |
26300 KB |
Output is correct |
53 |
Correct |
3 ms |
12888 KB |
Output is correct |
54 |
Correct |
4 ms |
13008 KB |
Output is correct |
55 |
Correct |
3 ms |
12892 KB |
Output is correct |
56 |
Correct |
4 ms |
13028 KB |
Output is correct |
57 |
Correct |
4 ms |
13148 KB |
Output is correct |
58 |
Correct |
4 ms |
13028 KB |
Output is correct |
59 |
Correct |
4 ms |
13144 KB |
Output is correct |
60 |
Correct |
4 ms |
13032 KB |
Output is correct |
61 |
Correct |
4 ms |
13148 KB |
Output is correct |
62 |
Correct |
4 ms |
13032 KB |
Output is correct |
63 |
Correct |
4 ms |
13144 KB |
Output is correct |
64 |
Correct |
4 ms |
13144 KB |
Output is correct |
65 |
Correct |
4 ms |
13148 KB |
Output is correct |
66 |
Correct |
4 ms |
13148 KB |
Output is correct |
67 |
Correct |
84 ms |
26760 KB |
Output is correct |
68 |
Correct |
75 ms |
26044 KB |
Output is correct |
69 |
Correct |
83 ms |
28580 KB |
Output is correct |
70 |
Correct |
90 ms |
28444 KB |
Output is correct |
71 |
Correct |
86 ms |
28592 KB |
Output is correct |
72 |
Correct |
88 ms |
27324 KB |
Output is correct |
73 |
Correct |
82 ms |
30396 KB |
Output is correct |
74 |
Correct |
70 ms |
24728 KB |
Output is correct |
75 |
Correct |
76 ms |
26836 KB |
Output is correct |
76 |
Correct |
81 ms |
25788 KB |
Output is correct |
77 |
Correct |
78 ms |
26856 KB |
Output is correct |
78 |
Correct |
78 ms |
26064 KB |
Output is correct |
79 |
Correct |
82 ms |
26944 KB |
Output is correct |
80 |
Correct |
58 ms |
26304 KB |
Output is correct |
81 |
Correct |
103 ms |
29888 KB |
Output is correct |
82 |
Correct |
102 ms |
29652 KB |
Output is correct |
83 |
Correct |
80 ms |
26908 KB |
Output is correct |
84 |
Correct |
72 ms |
26044 KB |
Output is correct |
85 |
Correct |
115 ms |
29320 KB |
Output is correct |
86 |
Correct |
77 ms |
27060 KB |
Output is correct |
87 |
Correct |
87 ms |
27612 KB |
Output is correct |
88 |
Correct |
79 ms |
25564 KB |
Output is correct |
89 |
Correct |
83 ms |
25912 KB |
Output is correct |
90 |
Correct |
104 ms |
27068 KB |
Output is correct |
91 |
Correct |
98 ms |
27584 KB |
Output is correct |
92 |
Correct |
113 ms |
28436 KB |
Output is correct |
93 |
Correct |
99 ms |
29804 KB |
Output is correct |
94 |
Correct |
95 ms |
27884 KB |
Output is correct |
95 |
Correct |
79 ms |
27064 KB |
Output is correct |
96 |
Correct |
69 ms |
25280 KB |
Output is correct |
97 |
Correct |
66 ms |
21184 KB |
Output is correct |
98 |
Correct |
96 ms |
29812 KB |
Output is correct |
99 |
Correct |
83 ms |
26304 KB |
Output is correct |
100 |
Correct |
48 ms |
16864 KB |
Output is correct |
101 |
Correct |
136 ms |
27840 KB |
Output is correct |
102 |
Correct |
114 ms |
25532 KB |
Output is correct |
103 |
Correct |
99 ms |
24764 KB |
Output is correct |
104 |
Correct |
119 ms |
27072 KB |
Output is correct |