#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,m,p[200005],r[200005];
ll c[200005],cnt[200005];
vector<int> ans[200005],adj[200005];
vector<pii> v;
int find(int x) {
while (x!=p[x]) x=p[x];
return x;
}
int unite(int x, int y) {
if (r[x]<r[y]) swap(x,y);
p[y]=x;
cnt[x]+=cnt[y];
if (r[x]==r[y]) ++r[x];
return x;
}
void add(int x) {
for (auto s : adj[x]) {
if (c[x]<c[s]) continue;
int S=find(s), X=find(x);
if (S!=X) {
if (cnt[S]>=c[x]) {
if (ans[X].size()<ans[S].size()) swap(ans[X],ans[S]);
for (auto k : ans[S]) ans[X].push_back(k);
}
int h=unite(X,S);
swap(ans[X],ans[h]);
}
}
}
bool Ans[200005];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
for (int i=1; i<=n; ++i) cin>>c[i], p[i]=i, cnt[i]=c[i], v.push_back(pii(c[i],i)), ans[i].push_back(i);
for (int i=0; i<m; ++i) {
int a,b; cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
sort(v.begin(),v.end());
for (auto s : v) add(s.second);
for (auto s : ans[find(v.back().second)]) Ans[s]=true;
for (int i=1; i<=n; ++i) {
if (Ans[i]) cout<<1;
else cout<<0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
6 ms |
9864 KB |
Output is correct |
7 |
Correct |
5 ms |
9908 KB |
Output is correct |
8 |
Correct |
5 ms |
9764 KB |
Output is correct |
9 |
Correct |
5 ms |
9812 KB |
Output is correct |
10 |
Correct |
5 ms |
9940 KB |
Output is correct |
11 |
Correct |
5 ms |
9940 KB |
Output is correct |
12 |
Correct |
6 ms |
9940 KB |
Output is correct |
13 |
Correct |
5 ms |
9940 KB |
Output is correct |
14 |
Correct |
5 ms |
9940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
140 ms |
30372 KB |
Output is correct |
4 |
Correct |
107 ms |
29664 KB |
Output is correct |
5 |
Correct |
124 ms |
31428 KB |
Output is correct |
6 |
Correct |
129 ms |
32188 KB |
Output is correct |
7 |
Correct |
131 ms |
32268 KB |
Output is correct |
8 |
Correct |
131 ms |
29964 KB |
Output is correct |
9 |
Correct |
130 ms |
32696 KB |
Output is correct |
10 |
Correct |
91 ms |
28644 KB |
Output is correct |
11 |
Correct |
118 ms |
30608 KB |
Output is correct |
12 |
Correct |
156 ms |
29764 KB |
Output is correct |
13 |
Correct |
100 ms |
29652 KB |
Output is correct |
14 |
Correct |
117 ms |
29660 KB |
Output is correct |
15 |
Correct |
111 ms |
29892 KB |
Output is correct |
16 |
Correct |
79 ms |
29732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
159 ms |
32764 KB |
Output is correct |
3 |
Correct |
159 ms |
33000 KB |
Output is correct |
4 |
Correct |
128 ms |
29860 KB |
Output is correct |
5 |
Correct |
106 ms |
29396 KB |
Output is correct |
6 |
Correct |
192 ms |
32796 KB |
Output is correct |
7 |
Correct |
131 ms |
29872 KB |
Output is correct |
8 |
Correct |
138 ms |
29904 KB |
Output is correct |
9 |
Correct |
88 ms |
29700 KB |
Output is correct |
10 |
Correct |
111 ms |
29672 KB |
Output is correct |
11 |
Correct |
144 ms |
30108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
175 ms |
30580 KB |
Output is correct |
3 |
Correct |
183 ms |
31032 KB |
Output is correct |
4 |
Correct |
162 ms |
32112 KB |
Output is correct |
5 |
Correct |
210 ms |
33352 KB |
Output is correct |
6 |
Correct |
166 ms |
30808 KB |
Output is correct |
7 |
Correct |
109 ms |
30648 KB |
Output is correct |
8 |
Correct |
87 ms |
29228 KB |
Output is correct |
9 |
Correct |
91 ms |
21000 KB |
Output is correct |
10 |
Correct |
178 ms |
34524 KB |
Output is correct |
11 |
Correct |
135 ms |
30152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
6 ms |
9864 KB |
Output is correct |
7 |
Correct |
5 ms |
9908 KB |
Output is correct |
8 |
Correct |
5 ms |
9764 KB |
Output is correct |
9 |
Correct |
5 ms |
9812 KB |
Output is correct |
10 |
Correct |
5 ms |
9940 KB |
Output is correct |
11 |
Correct |
5 ms |
9940 KB |
Output is correct |
12 |
Correct |
6 ms |
9940 KB |
Output is correct |
13 |
Correct |
5 ms |
9940 KB |
Output is correct |
14 |
Correct |
5 ms |
9940 KB |
Output is correct |
15 |
Correct |
6 ms |
9684 KB |
Output is correct |
16 |
Correct |
4 ms |
9684 KB |
Output is correct |
17 |
Correct |
140 ms |
30372 KB |
Output is correct |
18 |
Correct |
107 ms |
29664 KB |
Output is correct |
19 |
Correct |
124 ms |
31428 KB |
Output is correct |
20 |
Correct |
129 ms |
32188 KB |
Output is correct |
21 |
Correct |
131 ms |
32268 KB |
Output is correct |
22 |
Correct |
131 ms |
29964 KB |
Output is correct |
23 |
Correct |
130 ms |
32696 KB |
Output is correct |
24 |
Correct |
91 ms |
28644 KB |
Output is correct |
25 |
Correct |
118 ms |
30608 KB |
Output is correct |
26 |
Correct |
156 ms |
29764 KB |
Output is correct |
27 |
Correct |
100 ms |
29652 KB |
Output is correct |
28 |
Correct |
117 ms |
29660 KB |
Output is correct |
29 |
Correct |
111 ms |
29892 KB |
Output is correct |
30 |
Correct |
79 ms |
29732 KB |
Output is correct |
31 |
Correct |
6 ms |
9684 KB |
Output is correct |
32 |
Correct |
159 ms |
32764 KB |
Output is correct |
33 |
Correct |
159 ms |
33000 KB |
Output is correct |
34 |
Correct |
128 ms |
29860 KB |
Output is correct |
35 |
Correct |
106 ms |
29396 KB |
Output is correct |
36 |
Correct |
192 ms |
32796 KB |
Output is correct |
37 |
Correct |
131 ms |
29872 KB |
Output is correct |
38 |
Correct |
138 ms |
29904 KB |
Output is correct |
39 |
Correct |
88 ms |
29700 KB |
Output is correct |
40 |
Correct |
111 ms |
29672 KB |
Output is correct |
41 |
Correct |
144 ms |
30108 KB |
Output is correct |
42 |
Correct |
4 ms |
9684 KB |
Output is correct |
43 |
Correct |
175 ms |
30580 KB |
Output is correct |
44 |
Correct |
183 ms |
31032 KB |
Output is correct |
45 |
Correct |
162 ms |
32112 KB |
Output is correct |
46 |
Correct |
210 ms |
33352 KB |
Output is correct |
47 |
Correct |
166 ms |
30808 KB |
Output is correct |
48 |
Correct |
109 ms |
30648 KB |
Output is correct |
49 |
Correct |
87 ms |
29228 KB |
Output is correct |
50 |
Correct |
91 ms |
21000 KB |
Output is correct |
51 |
Correct |
178 ms |
34524 KB |
Output is correct |
52 |
Correct |
135 ms |
30152 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
4 ms |
9684 KB |
Output is correct |
55 |
Correct |
5 ms |
9684 KB |
Output is correct |
56 |
Correct |
5 ms |
9812 KB |
Output is correct |
57 |
Correct |
5 ms |
9940 KB |
Output is correct |
58 |
Correct |
5 ms |
9812 KB |
Output is correct |
59 |
Correct |
5 ms |
9812 KB |
Output is correct |
60 |
Correct |
5 ms |
9812 KB |
Output is correct |
61 |
Correct |
5 ms |
9880 KB |
Output is correct |
62 |
Correct |
5 ms |
9848 KB |
Output is correct |
63 |
Correct |
5 ms |
9940 KB |
Output is correct |
64 |
Correct |
5 ms |
9940 KB |
Output is correct |
65 |
Correct |
5 ms |
9812 KB |
Output is correct |
66 |
Correct |
5 ms |
9940 KB |
Output is correct |
67 |
Correct |
108 ms |
30368 KB |
Output is correct |
68 |
Correct |
104 ms |
29576 KB |
Output is correct |
69 |
Correct |
168 ms |
31532 KB |
Output is correct |
70 |
Correct |
159 ms |
32204 KB |
Output is correct |
71 |
Correct |
130 ms |
32216 KB |
Output is correct |
72 |
Correct |
131 ms |
29920 KB |
Output is correct |
73 |
Correct |
114 ms |
32700 KB |
Output is correct |
74 |
Correct |
87 ms |
28664 KB |
Output is correct |
75 |
Correct |
125 ms |
30632 KB |
Output is correct |
76 |
Correct |
133 ms |
29808 KB |
Output is correct |
77 |
Correct |
106 ms |
29604 KB |
Output is correct |
78 |
Correct |
141 ms |
29592 KB |
Output is correct |
79 |
Correct |
129 ms |
29976 KB |
Output is correct |
80 |
Correct |
80 ms |
29628 KB |
Output is correct |
81 |
Correct |
152 ms |
32856 KB |
Output is correct |
82 |
Correct |
168 ms |
32988 KB |
Output is correct |
83 |
Correct |
147 ms |
29908 KB |
Output is correct |
84 |
Correct |
96 ms |
29480 KB |
Output is correct |
85 |
Correct |
171 ms |
32852 KB |
Output is correct |
86 |
Correct |
132 ms |
29880 KB |
Output is correct |
87 |
Correct |
138 ms |
29884 KB |
Output is correct |
88 |
Correct |
123 ms |
29736 KB |
Output is correct |
89 |
Correct |
146 ms |
30172 KB |
Output is correct |
90 |
Correct |
163 ms |
30632 KB |
Output is correct |
91 |
Correct |
157 ms |
30968 KB |
Output is correct |
92 |
Correct |
179 ms |
32088 KB |
Output is correct |
93 |
Correct |
183 ms |
33260 KB |
Output is correct |
94 |
Correct |
158 ms |
30776 KB |
Output is correct |
95 |
Correct |
108 ms |
30672 KB |
Output is correct |
96 |
Correct |
95 ms |
29276 KB |
Output is correct |
97 |
Correct |
83 ms |
21048 KB |
Output is correct |
98 |
Correct |
157 ms |
34408 KB |
Output is correct |
99 |
Correct |
133 ms |
30160 KB |
Output is correct |
100 |
Correct |
35 ms |
12236 KB |
Output is correct |
101 |
Correct |
205 ms |
31356 KB |
Output is correct |
102 |
Correct |
136 ms |
26892 KB |
Output is correct |
103 |
Correct |
150 ms |
26920 KB |
Output is correct |
104 |
Correct |
168 ms |
30152 KB |
Output is correct |