#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
const int maxn5 = 3e5 + 10;
ll s[maxn5], sum[maxn5];
int cmp[maxn5];
bool mark[maxn5], seen[maxn5];
vector <int> adj[maxn5], av[maxn5];
vector <pair<int, int>> ver;
void merge(int a, int b){
if(av[a].size() < av[b].size())
swap(a, b);
for(auto u : av[b]){
cmp[u] = a;
av[a].pb(u);
}
sum[a] += sum[b];
av[b].clear();
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m; cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> s[i];
ver.pb({s[i], i});
}
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b;
a--; b--;
adj[a].pb(b);
adj[b].pb(a);
}
sort(all(ver));
memset(mark, true, sizeof mark);
for(int i = 0; i < n; i++){
cmp[i] = i;
av[i].pb(i);
sum[i] = s[i];
}
for(auto [val, v] : ver){
seen[v] = true;
for(auto u : adj[v]) if(cmp[u] != cmp[v] && seen[u]){
if(sum[cmp[u]] < s[v])
for(auto z : av[cmp[u]])
mark[z] = false;
merge(cmp[u], cmp[v]);
}
}
for(int i = 0; i < n; i++)
cout << mark[i];
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14676 KB |
Output is correct |
2 |
Correct |
7 ms |
14676 KB |
Output is correct |
3 |
Correct |
7 ms |
14676 KB |
Output is correct |
4 |
Correct |
8 ms |
14808 KB |
Output is correct |
5 |
Correct |
10 ms |
14892 KB |
Output is correct |
6 |
Correct |
9 ms |
14804 KB |
Output is correct |
7 |
Correct |
9 ms |
14840 KB |
Output is correct |
8 |
Correct |
9 ms |
14804 KB |
Output is correct |
9 |
Correct |
10 ms |
14868 KB |
Output is correct |
10 |
Correct |
8 ms |
14868 KB |
Output is correct |
11 |
Correct |
9 ms |
14968 KB |
Output is correct |
12 |
Correct |
8 ms |
14932 KB |
Output is correct |
13 |
Correct |
9 ms |
14804 KB |
Output is correct |
14 |
Correct |
10 ms |
14940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14676 KB |
Output is correct |
2 |
Correct |
7 ms |
14676 KB |
Output is correct |
3 |
Correct |
140 ms |
34908 KB |
Output is correct |
4 |
Correct |
136 ms |
34936 KB |
Output is correct |
5 |
Correct |
171 ms |
38740 KB |
Output is correct |
6 |
Correct |
174 ms |
39564 KB |
Output is correct |
7 |
Correct |
183 ms |
39620 KB |
Output is correct |
8 |
Correct |
174 ms |
34980 KB |
Output is correct |
9 |
Correct |
157 ms |
43784 KB |
Output is correct |
10 |
Correct |
151 ms |
35672 KB |
Output is correct |
11 |
Correct |
138 ms |
35700 KB |
Output is correct |
12 |
Correct |
217 ms |
35912 KB |
Output is correct |
13 |
Correct |
180 ms |
34872 KB |
Output is correct |
14 |
Correct |
168 ms |
34904 KB |
Output is correct |
15 |
Correct |
140 ms |
34924 KB |
Output is correct |
16 |
Correct |
90 ms |
34712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14676 KB |
Output is correct |
2 |
Correct |
242 ms |
41220 KB |
Output is correct |
3 |
Correct |
223 ms |
41172 KB |
Output is correct |
4 |
Correct |
175 ms |
34904 KB |
Output is correct |
5 |
Correct |
144 ms |
34920 KB |
Output is correct |
6 |
Correct |
203 ms |
41196 KB |
Output is correct |
7 |
Correct |
184 ms |
34816 KB |
Output is correct |
8 |
Correct |
166 ms |
34872 KB |
Output is correct |
9 |
Correct |
91 ms |
34632 KB |
Output is correct |
10 |
Correct |
157 ms |
34960 KB |
Output is correct |
11 |
Correct |
194 ms |
35816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14676 KB |
Output is correct |
2 |
Correct |
226 ms |
36720 KB |
Output is correct |
3 |
Correct |
235 ms |
37352 KB |
Output is correct |
4 |
Correct |
231 ms |
38504 KB |
Output is correct |
5 |
Correct |
190 ms |
37464 KB |
Output is correct |
6 |
Correct |
165 ms |
35060 KB |
Output is correct |
7 |
Correct |
132 ms |
35708 KB |
Output is correct |
8 |
Correct |
95 ms |
34916 KB |
Output is correct |
9 |
Correct |
102 ms |
26256 KB |
Output is correct |
10 |
Correct |
180 ms |
38412 KB |
Output is correct |
11 |
Correct |
163 ms |
35648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14676 KB |
Output is correct |
2 |
Correct |
7 ms |
14676 KB |
Output is correct |
3 |
Correct |
7 ms |
14676 KB |
Output is correct |
4 |
Correct |
8 ms |
14808 KB |
Output is correct |
5 |
Correct |
10 ms |
14892 KB |
Output is correct |
6 |
Correct |
9 ms |
14804 KB |
Output is correct |
7 |
Correct |
9 ms |
14840 KB |
Output is correct |
8 |
Correct |
9 ms |
14804 KB |
Output is correct |
9 |
Correct |
10 ms |
14868 KB |
Output is correct |
10 |
Correct |
8 ms |
14868 KB |
Output is correct |
11 |
Correct |
9 ms |
14968 KB |
Output is correct |
12 |
Correct |
8 ms |
14932 KB |
Output is correct |
13 |
Correct |
9 ms |
14804 KB |
Output is correct |
14 |
Correct |
10 ms |
14940 KB |
Output is correct |
15 |
Correct |
8 ms |
14676 KB |
Output is correct |
16 |
Correct |
7 ms |
14676 KB |
Output is correct |
17 |
Correct |
140 ms |
34908 KB |
Output is correct |
18 |
Correct |
136 ms |
34936 KB |
Output is correct |
19 |
Correct |
171 ms |
38740 KB |
Output is correct |
20 |
Correct |
174 ms |
39564 KB |
Output is correct |
21 |
Correct |
183 ms |
39620 KB |
Output is correct |
22 |
Correct |
174 ms |
34980 KB |
Output is correct |
23 |
Correct |
157 ms |
43784 KB |
Output is correct |
24 |
Correct |
151 ms |
35672 KB |
Output is correct |
25 |
Correct |
138 ms |
35700 KB |
Output is correct |
26 |
Correct |
217 ms |
35912 KB |
Output is correct |
27 |
Correct |
180 ms |
34872 KB |
Output is correct |
28 |
Correct |
168 ms |
34904 KB |
Output is correct |
29 |
Correct |
140 ms |
34924 KB |
Output is correct |
30 |
Correct |
90 ms |
34712 KB |
Output is correct |
31 |
Correct |
7 ms |
14676 KB |
Output is correct |
32 |
Correct |
242 ms |
41220 KB |
Output is correct |
33 |
Correct |
223 ms |
41172 KB |
Output is correct |
34 |
Correct |
175 ms |
34904 KB |
Output is correct |
35 |
Correct |
144 ms |
34920 KB |
Output is correct |
36 |
Correct |
203 ms |
41196 KB |
Output is correct |
37 |
Correct |
184 ms |
34816 KB |
Output is correct |
38 |
Correct |
166 ms |
34872 KB |
Output is correct |
39 |
Correct |
91 ms |
34632 KB |
Output is correct |
40 |
Correct |
157 ms |
34960 KB |
Output is correct |
41 |
Correct |
194 ms |
35816 KB |
Output is correct |
42 |
Correct |
7 ms |
14676 KB |
Output is correct |
43 |
Correct |
226 ms |
36720 KB |
Output is correct |
44 |
Correct |
235 ms |
37352 KB |
Output is correct |
45 |
Correct |
231 ms |
38504 KB |
Output is correct |
46 |
Correct |
190 ms |
37464 KB |
Output is correct |
47 |
Correct |
165 ms |
35060 KB |
Output is correct |
48 |
Correct |
132 ms |
35708 KB |
Output is correct |
49 |
Correct |
95 ms |
34916 KB |
Output is correct |
50 |
Correct |
102 ms |
26256 KB |
Output is correct |
51 |
Correct |
180 ms |
38412 KB |
Output is correct |
52 |
Correct |
163 ms |
35648 KB |
Output is correct |
53 |
Correct |
7 ms |
14676 KB |
Output is correct |
54 |
Correct |
9 ms |
14676 KB |
Output is correct |
55 |
Correct |
8 ms |
14676 KB |
Output is correct |
56 |
Correct |
9 ms |
14804 KB |
Output is correct |
57 |
Correct |
9 ms |
14932 KB |
Output is correct |
58 |
Correct |
8 ms |
14804 KB |
Output is correct |
59 |
Correct |
9 ms |
14804 KB |
Output is correct |
60 |
Correct |
11 ms |
14804 KB |
Output is correct |
61 |
Correct |
8 ms |
14900 KB |
Output is correct |
62 |
Correct |
9 ms |
15060 KB |
Output is correct |
63 |
Correct |
9 ms |
14932 KB |
Output is correct |
64 |
Correct |
9 ms |
14932 KB |
Output is correct |
65 |
Correct |
9 ms |
14912 KB |
Output is correct |
66 |
Correct |
9 ms |
14932 KB |
Output is correct |
67 |
Correct |
150 ms |
34928 KB |
Output is correct |
68 |
Correct |
148 ms |
35008 KB |
Output is correct |
69 |
Correct |
169 ms |
38832 KB |
Output is correct |
70 |
Correct |
178 ms |
39572 KB |
Output is correct |
71 |
Correct |
175 ms |
39548 KB |
Output is correct |
72 |
Correct |
144 ms |
34900 KB |
Output is correct |
73 |
Correct |
154 ms |
43836 KB |
Output is correct |
74 |
Correct |
156 ms |
35656 KB |
Output is correct |
75 |
Correct |
142 ms |
35648 KB |
Output is correct |
76 |
Correct |
154 ms |
35852 KB |
Output is correct |
77 |
Correct |
130 ms |
34924 KB |
Output is correct |
78 |
Correct |
138 ms |
34820 KB |
Output is correct |
79 |
Correct |
134 ms |
34808 KB |
Output is correct |
80 |
Correct |
90 ms |
34708 KB |
Output is correct |
81 |
Correct |
205 ms |
41208 KB |
Output is correct |
82 |
Correct |
206 ms |
41208 KB |
Output is correct |
83 |
Correct |
154 ms |
34912 KB |
Output is correct |
84 |
Correct |
133 ms |
34928 KB |
Output is correct |
85 |
Correct |
209 ms |
41208 KB |
Output is correct |
86 |
Correct |
157 ms |
34820 KB |
Output is correct |
87 |
Correct |
145 ms |
34876 KB |
Output is correct |
88 |
Correct |
141 ms |
34816 KB |
Output is correct |
89 |
Correct |
163 ms |
35780 KB |
Output is correct |
90 |
Correct |
212 ms |
36672 KB |
Output is correct |
91 |
Correct |
208 ms |
37344 KB |
Output is correct |
92 |
Correct |
223 ms |
38468 KB |
Output is correct |
93 |
Correct |
189 ms |
37472 KB |
Output is correct |
94 |
Correct |
165 ms |
35008 KB |
Output is correct |
95 |
Correct |
146 ms |
35608 KB |
Output is correct |
96 |
Correct |
97 ms |
34912 KB |
Output is correct |
97 |
Correct |
111 ms |
26284 KB |
Output is correct |
98 |
Correct |
169 ms |
38504 KB |
Output is correct |
99 |
Correct |
154 ms |
35652 KB |
Output is correct |
100 |
Correct |
43 ms |
17064 KB |
Output is correct |
101 |
Correct |
237 ms |
38068 KB |
Output is correct |
102 |
Correct |
152 ms |
31084 KB |
Output is correct |
103 |
Correct |
182 ms |
32248 KB |
Output is correct |
104 |
Correct |
226 ms |
35928 KB |
Output is correct |