#include <bits/stdc++.h>
using namespace std;
int n,m;
int b[200001];
pair<int,int> a[200001];
vector<int> v[200001];
void read()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i].first;
b[i]=a[i].first;
a[i].second=i;
}
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
}
pair<int,int> p[200001];
long long sz[200001];
pair<int,int> parent(int x)
{
if(x==p[x].first)return p[x];
pair<int,int> y=parent(p[x].first);
y.second=max(y.second,p[x].second);
return p[x]=y;
}
void unite(int i,int j)
{
pair<int,int> pi=parent(i);
pair<int,int> pj=parent(j);
if(pi.first==pj.first)return;
//cout<<i<<" "<<j<<" "<<pi.first<<" "<<pj.first<<endl;
i=pi.first;
j=pj.first;
sz[i]+=sz[j];
p[j].first=i;
}
void solve()
{
for(int i=1;i<=n;i++)
{
p[i].first=i;
sz[i]=a[i].first;
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)
{
int vr=a[i].second;
//cout<<a[i].first<<" "<<vr<<"!"<<endl;
for(int j=0;j<v[vr].size();j++)
{
int nb=v[vr][j];
pair<int,int> pnb=parent(nb);
nb=pnb.first;
if(sz[nb]<sz[vr])
p[nb].second=1;
}
for(int j=0;j<v[vr].size();j++)
{
int nb=v[vr][j];
if(b[nb]<=b[vr])
unite(vr,nb);
}
}
for(int i=1;i<=n;i++)
{
pair<int,int> p=parent(i);
cout<<(1^p.second);
}
cout<<endl;
}
int main()
{
read();
solve();
return 0;
}
/*
7 6
2 2 1 1 8 5 5
1 2
2 3
3 4
4 5
5 6
6 7
*/
Compilation message
island.cpp: In function 'void solve()':
island.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j=0;j<v[vr].size();j++)
| ~^~~~~~~~~~~~~
island.cpp:74:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int j=0;j<v[vr].size();j++)
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8528 KB |
Output is correct |
2 |
Correct |
2 ms |
8648 KB |
Output is correct |
3 |
Correct |
2 ms |
8528 KB |
Output is correct |
4 |
Correct |
3 ms |
8528 KB |
Output is correct |
5 |
Correct |
4 ms |
8784 KB |
Output is correct |
6 |
Correct |
3 ms |
8528 KB |
Output is correct |
7 |
Correct |
3 ms |
8664 KB |
Output is correct |
8 |
Correct |
3 ms |
8528 KB |
Output is correct |
9 |
Correct |
3 ms |
8784 KB |
Output is correct |
10 |
Correct |
4 ms |
8784 KB |
Output is correct |
11 |
Correct |
4 ms |
8784 KB |
Output is correct |
12 |
Correct |
4 ms |
8528 KB |
Output is correct |
13 |
Correct |
4 ms |
8696 KB |
Output is correct |
14 |
Correct |
4 ms |
8636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8528 KB |
Output is correct |
2 |
Correct |
2 ms |
8528 KB |
Output is correct |
3 |
Correct |
200 ms |
16872 KB |
Output is correct |
4 |
Correct |
148 ms |
19864 KB |
Output is correct |
5 |
Correct |
193 ms |
20300 KB |
Output is correct |
6 |
Correct |
179 ms |
21320 KB |
Output is correct |
7 |
Correct |
163 ms |
21320 KB |
Output is correct |
8 |
Correct |
184 ms |
21320 KB |
Output is correct |
9 |
Correct |
180 ms |
21384 KB |
Output is correct |
10 |
Correct |
155 ms |
21180 KB |
Output is correct |
11 |
Correct |
165 ms |
21080 KB |
Output is correct |
12 |
Correct |
160 ms |
19784 KB |
Output is correct |
13 |
Correct |
162 ms |
19528 KB |
Output is correct |
14 |
Correct |
165 ms |
20044 KB |
Output is correct |
15 |
Correct |
179 ms |
21280 KB |
Output is correct |
16 |
Correct |
123 ms |
20552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8528 KB |
Output is correct |
2 |
Correct |
191 ms |
16976 KB |
Output is correct |
3 |
Correct |
173 ms |
21320 KB |
Output is correct |
4 |
Correct |
164 ms |
21320 KB |
Output is correct |
5 |
Correct |
135 ms |
19736 KB |
Output is correct |
6 |
Correct |
180 ms |
21320 KB |
Output is correct |
7 |
Correct |
185 ms |
21320 KB |
Output is correct |
8 |
Correct |
175 ms |
21324 KB |
Output is correct |
9 |
Correct |
133 ms |
20552 KB |
Output is correct |
10 |
Correct |
142 ms |
23732 KB |
Output is correct |
11 |
Correct |
159 ms |
20480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8528 KB |
Output is correct |
2 |
Correct |
191 ms |
16968 KB |
Output is correct |
3 |
Correct |
226 ms |
20552 KB |
Output is correct |
4 |
Correct |
237 ms |
21320 KB |
Output is correct |
5 |
Correct |
222 ms |
20296 KB |
Output is correct |
6 |
Correct |
210 ms |
20372 KB |
Output is correct |
7 |
Correct |
197 ms |
22972 KB |
Output is correct |
8 |
Correct |
135 ms |
23372 KB |
Output is correct |
9 |
Correct |
124 ms |
15944 KB |
Output is correct |
10 |
Correct |
145 ms |
19528 KB |
Output is correct |
11 |
Correct |
144 ms |
20812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8528 KB |
Output is correct |
2 |
Correct |
2 ms |
8648 KB |
Output is correct |
3 |
Correct |
2 ms |
8528 KB |
Output is correct |
4 |
Correct |
3 ms |
8528 KB |
Output is correct |
5 |
Correct |
4 ms |
8784 KB |
Output is correct |
6 |
Correct |
3 ms |
8528 KB |
Output is correct |
7 |
Correct |
3 ms |
8664 KB |
Output is correct |
8 |
Correct |
3 ms |
8528 KB |
Output is correct |
9 |
Correct |
3 ms |
8784 KB |
Output is correct |
10 |
Correct |
4 ms |
8784 KB |
Output is correct |
11 |
Correct |
4 ms |
8784 KB |
Output is correct |
12 |
Correct |
4 ms |
8528 KB |
Output is correct |
13 |
Correct |
4 ms |
8696 KB |
Output is correct |
14 |
Correct |
4 ms |
8636 KB |
Output is correct |
15 |
Correct |
2 ms |
8528 KB |
Output is correct |
16 |
Correct |
2 ms |
8528 KB |
Output is correct |
17 |
Correct |
200 ms |
16872 KB |
Output is correct |
18 |
Correct |
148 ms |
19864 KB |
Output is correct |
19 |
Correct |
193 ms |
20300 KB |
Output is correct |
20 |
Correct |
179 ms |
21320 KB |
Output is correct |
21 |
Correct |
163 ms |
21320 KB |
Output is correct |
22 |
Correct |
184 ms |
21320 KB |
Output is correct |
23 |
Correct |
180 ms |
21384 KB |
Output is correct |
24 |
Correct |
155 ms |
21180 KB |
Output is correct |
25 |
Correct |
165 ms |
21080 KB |
Output is correct |
26 |
Correct |
160 ms |
19784 KB |
Output is correct |
27 |
Correct |
162 ms |
19528 KB |
Output is correct |
28 |
Correct |
165 ms |
20044 KB |
Output is correct |
29 |
Correct |
179 ms |
21280 KB |
Output is correct |
30 |
Correct |
123 ms |
20552 KB |
Output is correct |
31 |
Correct |
2 ms |
8528 KB |
Output is correct |
32 |
Correct |
191 ms |
16976 KB |
Output is correct |
33 |
Correct |
173 ms |
21320 KB |
Output is correct |
34 |
Correct |
164 ms |
21320 KB |
Output is correct |
35 |
Correct |
135 ms |
19736 KB |
Output is correct |
36 |
Correct |
180 ms |
21320 KB |
Output is correct |
37 |
Correct |
185 ms |
21320 KB |
Output is correct |
38 |
Correct |
175 ms |
21324 KB |
Output is correct |
39 |
Correct |
133 ms |
20552 KB |
Output is correct |
40 |
Correct |
142 ms |
23732 KB |
Output is correct |
41 |
Correct |
159 ms |
20480 KB |
Output is correct |
42 |
Correct |
2 ms |
8528 KB |
Output is correct |
43 |
Correct |
191 ms |
16968 KB |
Output is correct |
44 |
Correct |
226 ms |
20552 KB |
Output is correct |
45 |
Correct |
237 ms |
21320 KB |
Output is correct |
46 |
Correct |
222 ms |
20296 KB |
Output is correct |
47 |
Correct |
210 ms |
20372 KB |
Output is correct |
48 |
Correct |
197 ms |
22972 KB |
Output is correct |
49 |
Correct |
135 ms |
23372 KB |
Output is correct |
50 |
Correct |
124 ms |
15944 KB |
Output is correct |
51 |
Correct |
145 ms |
19528 KB |
Output is correct |
52 |
Correct |
144 ms |
20812 KB |
Output is correct |
53 |
Correct |
2 ms |
8528 KB |
Output is correct |
54 |
Correct |
2 ms |
8528 KB |
Output is correct |
55 |
Correct |
2 ms |
8528 KB |
Output is correct |
56 |
Correct |
4 ms |
8528 KB |
Output is correct |
57 |
Correct |
4 ms |
8784 KB |
Output is correct |
58 |
Correct |
3 ms |
8672 KB |
Output is correct |
59 |
Correct |
4 ms |
8528 KB |
Output is correct |
60 |
Correct |
4 ms |
8528 KB |
Output is correct |
61 |
Correct |
3 ms |
8784 KB |
Output is correct |
62 |
Correct |
3 ms |
8784 KB |
Output is correct |
63 |
Correct |
4 ms |
8784 KB |
Output is correct |
64 |
Correct |
4 ms |
8528 KB |
Output is correct |
65 |
Correct |
3 ms |
8528 KB |
Output is correct |
66 |
Correct |
5 ms |
8528 KB |
Output is correct |
67 |
Correct |
157 ms |
21320 KB |
Output is correct |
68 |
Correct |
152 ms |
20040 KB |
Output is correct |
69 |
Correct |
160 ms |
20656 KB |
Output is correct |
70 |
Correct |
159 ms |
21320 KB |
Output is correct |
71 |
Correct |
194 ms |
21320 KB |
Output is correct |
72 |
Correct |
196 ms |
21384 KB |
Output is correct |
73 |
Correct |
178 ms |
21064 KB |
Output is correct |
74 |
Correct |
155 ms |
21180 KB |
Output is correct |
75 |
Correct |
158 ms |
21180 KB |
Output is correct |
76 |
Correct |
145 ms |
18940 KB |
Output is correct |
77 |
Correct |
140 ms |
19780 KB |
Output is correct |
78 |
Correct |
135 ms |
19784 KB |
Output is correct |
79 |
Correct |
155 ms |
20296 KB |
Output is correct |
80 |
Correct |
132 ms |
20552 KB |
Output is correct |
81 |
Correct |
219 ms |
20808 KB |
Output is correct |
82 |
Correct |
207 ms |
21308 KB |
Output is correct |
83 |
Correct |
216 ms |
21320 KB |
Output is correct |
84 |
Correct |
159 ms |
19784 KB |
Output is correct |
85 |
Correct |
204 ms |
21332 KB |
Output is correct |
86 |
Correct |
162 ms |
21288 KB |
Output is correct |
87 |
Correct |
185 ms |
21320 KB |
Output is correct |
88 |
Correct |
165 ms |
23960 KB |
Output is correct |
89 |
Correct |
164 ms |
20808 KB |
Output is correct |
90 |
Correct |
204 ms |
21484 KB |
Output is correct |
91 |
Correct |
194 ms |
21372 KB |
Output is correct |
92 |
Correct |
193 ms |
21320 KB |
Output is correct |
93 |
Correct |
195 ms |
21308 KB |
Output is correct |
94 |
Correct |
174 ms |
20364 KB |
Output is correct |
95 |
Correct |
154 ms |
22716 KB |
Output is correct |
96 |
Correct |
127 ms |
23364 KB |
Output is correct |
97 |
Correct |
129 ms |
16252 KB |
Output is correct |
98 |
Correct |
194 ms |
19528 KB |
Output is correct |
99 |
Correct |
200 ms |
20808 KB |
Output is correct |
100 |
Correct |
74 ms |
12872 KB |
Output is correct |
101 |
Correct |
202 ms |
21332 KB |
Output is correct |
102 |
Correct |
192 ms |
18916 KB |
Output is correct |
103 |
Correct |
180 ms |
19784 KB |
Output is correct |
104 |
Correct |
182 ms |
21324 KB |
Output is correct |