#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9+7
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e4+7;
const int nax = 4e5+5;
typedef complex<int> Point;
#define X real()
#define Y imag()
vii s;
vi adj[nax], nds[nax];
ll ans[nax];
ll p[nax], sz[nax];
int find_set(int v) {
if (v == p[v])
return v;
return p[v] = find_set(p[v]);
}
void union_sets(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b){
if(nds[b].size() > nds[a].size()) swap(nds[a],nds[b]);
for(auto x : nds[b]) nds[a].pb(x);
p[b] = a;
sz[a] += sz[b];
}
}
int main(){
optimise;
int n,m;
cin >>n >> m;
for (int i = 0; i < n; ++i)
{
int val;
cin >> val;
sz[i] = val;
p[i] = i;
nds[i].pb(i);
s.pb({val,i});
}
for (int i = 0; i < m; ++i)
{
int a,b;
cin >> a >> b;
a--,b--;
if(mp(sz[a],a) < mp(sz[b],b)) swap(a,b);
adj[a].pb(b);
}
sort(s.begin(), s.end());
for (int i = 0; i < n; ++i)
{
int u = find_set(s[i].se);
for(auto x : adj[u]){
x = find_set(x);
if(sz[u] > sz[x]) nds[x].clear();
}
for(auto x : adj[u]) union_sets(x,u);
}
for(auto x: nds[find_set(0)]) ans[x] = 1;
for (int i = 0; i < n; ++i)
{
cout << ans[i];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19116 KB |
Output is correct |
2 |
Correct |
12 ms |
19072 KB |
Output is correct |
3 |
Correct |
13 ms |
19132 KB |
Output is correct |
4 |
Correct |
12 ms |
19288 KB |
Output is correct |
5 |
Correct |
11 ms |
19284 KB |
Output is correct |
6 |
Correct |
11 ms |
19156 KB |
Output is correct |
7 |
Correct |
11 ms |
19156 KB |
Output is correct |
8 |
Correct |
11 ms |
19192 KB |
Output is correct |
9 |
Correct |
11 ms |
19264 KB |
Output is correct |
10 |
Correct |
12 ms |
19284 KB |
Output is correct |
11 |
Correct |
10 ms |
19320 KB |
Output is correct |
12 |
Correct |
11 ms |
19260 KB |
Output is correct |
13 |
Correct |
11 ms |
19208 KB |
Output is correct |
14 |
Correct |
11 ms |
19284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
139 ms |
37640 KB |
Output is correct |
4 |
Correct |
129 ms |
38356 KB |
Output is correct |
5 |
Correct |
169 ms |
38208 KB |
Output is correct |
6 |
Correct |
152 ms |
38908 KB |
Output is correct |
7 |
Correct |
163 ms |
38892 KB |
Output is correct |
8 |
Correct |
156 ms |
39892 KB |
Output is correct |
9 |
Correct |
137 ms |
38592 KB |
Output is correct |
10 |
Correct |
105 ms |
32008 KB |
Output is correct |
11 |
Correct |
147 ms |
39908 KB |
Output is correct |
12 |
Correct |
142 ms |
37176 KB |
Output is correct |
13 |
Correct |
132 ms |
38292 KB |
Output is correct |
14 |
Correct |
122 ms |
38336 KB |
Output is correct |
15 |
Correct |
135 ms |
39932 KB |
Output is correct |
16 |
Correct |
103 ms |
39608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19016 KB |
Output is correct |
2 |
Correct |
189 ms |
40140 KB |
Output is correct |
3 |
Correct |
185 ms |
40144 KB |
Output is correct |
4 |
Correct |
161 ms |
39836 KB |
Output is correct |
5 |
Correct |
130 ms |
38096 KB |
Output is correct |
6 |
Correct |
182 ms |
39936 KB |
Output is correct |
7 |
Correct |
179 ms |
39864 KB |
Output is correct |
8 |
Correct |
158 ms |
39884 KB |
Output is correct |
9 |
Correct |
95 ms |
39708 KB |
Output is correct |
10 |
Correct |
129 ms |
36444 KB |
Output is correct |
11 |
Correct |
183 ms |
36272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
209 ms |
37540 KB |
Output is correct |
3 |
Correct |
196 ms |
37960 KB |
Output is correct |
4 |
Correct |
193 ms |
39000 KB |
Output is correct |
5 |
Correct |
183 ms |
40240 KB |
Output is correct |
6 |
Correct |
163 ms |
37816 KB |
Output is correct |
7 |
Correct |
122 ms |
38536 KB |
Output is correct |
8 |
Correct |
93 ms |
38520 KB |
Output is correct |
9 |
Correct |
122 ms |
28932 KB |
Output is correct |
10 |
Correct |
168 ms |
39580 KB |
Output is correct |
11 |
Correct |
145 ms |
36248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19116 KB |
Output is correct |
2 |
Correct |
12 ms |
19072 KB |
Output is correct |
3 |
Correct |
13 ms |
19132 KB |
Output is correct |
4 |
Correct |
12 ms |
19288 KB |
Output is correct |
5 |
Correct |
11 ms |
19284 KB |
Output is correct |
6 |
Correct |
11 ms |
19156 KB |
Output is correct |
7 |
Correct |
11 ms |
19156 KB |
Output is correct |
8 |
Correct |
11 ms |
19192 KB |
Output is correct |
9 |
Correct |
11 ms |
19264 KB |
Output is correct |
10 |
Correct |
12 ms |
19284 KB |
Output is correct |
11 |
Correct |
10 ms |
19320 KB |
Output is correct |
12 |
Correct |
11 ms |
19260 KB |
Output is correct |
13 |
Correct |
11 ms |
19208 KB |
Output is correct |
14 |
Correct |
11 ms |
19284 KB |
Output is correct |
15 |
Correct |
10 ms |
19028 KB |
Output is correct |
16 |
Correct |
10 ms |
19028 KB |
Output is correct |
17 |
Correct |
139 ms |
37640 KB |
Output is correct |
18 |
Correct |
129 ms |
38356 KB |
Output is correct |
19 |
Correct |
169 ms |
38208 KB |
Output is correct |
20 |
Correct |
152 ms |
38908 KB |
Output is correct |
21 |
Correct |
163 ms |
38892 KB |
Output is correct |
22 |
Correct |
156 ms |
39892 KB |
Output is correct |
23 |
Correct |
137 ms |
38592 KB |
Output is correct |
24 |
Correct |
105 ms |
32008 KB |
Output is correct |
25 |
Correct |
147 ms |
39908 KB |
Output is correct |
26 |
Correct |
142 ms |
37176 KB |
Output is correct |
27 |
Correct |
132 ms |
38292 KB |
Output is correct |
28 |
Correct |
122 ms |
38336 KB |
Output is correct |
29 |
Correct |
135 ms |
39932 KB |
Output is correct |
30 |
Correct |
103 ms |
39608 KB |
Output is correct |
31 |
Correct |
10 ms |
19016 KB |
Output is correct |
32 |
Correct |
189 ms |
40140 KB |
Output is correct |
33 |
Correct |
185 ms |
40144 KB |
Output is correct |
34 |
Correct |
161 ms |
39836 KB |
Output is correct |
35 |
Correct |
130 ms |
38096 KB |
Output is correct |
36 |
Correct |
182 ms |
39936 KB |
Output is correct |
37 |
Correct |
179 ms |
39864 KB |
Output is correct |
38 |
Correct |
158 ms |
39884 KB |
Output is correct |
39 |
Correct |
95 ms |
39708 KB |
Output is correct |
40 |
Correct |
129 ms |
36444 KB |
Output is correct |
41 |
Correct |
183 ms |
36272 KB |
Output is correct |
42 |
Correct |
10 ms |
19028 KB |
Output is correct |
43 |
Correct |
209 ms |
37540 KB |
Output is correct |
44 |
Correct |
196 ms |
37960 KB |
Output is correct |
45 |
Correct |
193 ms |
39000 KB |
Output is correct |
46 |
Correct |
183 ms |
40240 KB |
Output is correct |
47 |
Correct |
163 ms |
37816 KB |
Output is correct |
48 |
Correct |
122 ms |
38536 KB |
Output is correct |
49 |
Correct |
93 ms |
38520 KB |
Output is correct |
50 |
Correct |
122 ms |
28932 KB |
Output is correct |
51 |
Correct |
168 ms |
39580 KB |
Output is correct |
52 |
Correct |
145 ms |
36248 KB |
Output is correct |
53 |
Correct |
11 ms |
19028 KB |
Output is correct |
54 |
Correct |
12 ms |
19084 KB |
Output is correct |
55 |
Correct |
11 ms |
19032 KB |
Output is correct |
56 |
Correct |
11 ms |
19284 KB |
Output is correct |
57 |
Correct |
12 ms |
19284 KB |
Output is correct |
58 |
Correct |
12 ms |
19196 KB |
Output is correct |
59 |
Correct |
11 ms |
19264 KB |
Output is correct |
60 |
Correct |
11 ms |
19156 KB |
Output is correct |
61 |
Correct |
13 ms |
19284 KB |
Output is correct |
62 |
Correct |
10 ms |
19284 KB |
Output is correct |
63 |
Correct |
10 ms |
19284 KB |
Output is correct |
64 |
Correct |
10 ms |
19316 KB |
Output is correct |
65 |
Correct |
12 ms |
19216 KB |
Output is correct |
66 |
Correct |
11 ms |
19276 KB |
Output is correct |
67 |
Correct |
138 ms |
37748 KB |
Output is correct |
68 |
Correct |
124 ms |
38328 KB |
Output is correct |
69 |
Correct |
149 ms |
38356 KB |
Output is correct |
70 |
Correct |
195 ms |
38840 KB |
Output is correct |
71 |
Correct |
147 ms |
38952 KB |
Output is correct |
72 |
Correct |
162 ms |
39884 KB |
Output is correct |
73 |
Correct |
125 ms |
38632 KB |
Output is correct |
74 |
Correct |
105 ms |
32056 KB |
Output is correct |
75 |
Correct |
136 ms |
39804 KB |
Output is correct |
76 |
Correct |
163 ms |
37252 KB |
Output is correct |
77 |
Correct |
134 ms |
38456 KB |
Output is correct |
78 |
Correct |
133 ms |
38412 KB |
Output is correct |
79 |
Correct |
138 ms |
39900 KB |
Output is correct |
80 |
Correct |
92 ms |
39712 KB |
Output is correct |
81 |
Correct |
182 ms |
39904 KB |
Output is correct |
82 |
Correct |
185 ms |
40120 KB |
Output is correct |
83 |
Correct |
152 ms |
39920 KB |
Output is correct |
84 |
Correct |
122 ms |
38004 KB |
Output is correct |
85 |
Correct |
190 ms |
39916 KB |
Output is correct |
86 |
Correct |
147 ms |
39924 KB |
Output is correct |
87 |
Correct |
139 ms |
39820 KB |
Output is correct |
88 |
Correct |
121 ms |
36416 KB |
Output is correct |
89 |
Correct |
157 ms |
36412 KB |
Output is correct |
90 |
Correct |
184 ms |
37564 KB |
Output is correct |
91 |
Correct |
212 ms |
37928 KB |
Output is correct |
92 |
Correct |
218 ms |
39100 KB |
Output is correct |
93 |
Correct |
176 ms |
40152 KB |
Output is correct |
94 |
Correct |
150 ms |
37832 KB |
Output is correct |
95 |
Correct |
130 ms |
38536 KB |
Output is correct |
96 |
Correct |
102 ms |
38564 KB |
Output is correct |
97 |
Correct |
99 ms |
28920 KB |
Output is correct |
98 |
Correct |
170 ms |
39480 KB |
Output is correct |
99 |
Correct |
150 ms |
36344 KB |
Output is correct |
100 |
Correct |
45 ms |
20812 KB |
Output is correct |
101 |
Correct |
214 ms |
38284 KB |
Output is correct |
102 |
Correct |
152 ms |
34324 KB |
Output is correct |
103 |
Correct |
161 ms |
34216 KB |
Output is correct |
104 |
Correct |
200 ms |
37028 KB |
Output is correct |