#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int>link[200100];
vector<pair<int,int>>x;
int uf[200100];
int sum[200100];
vector<int>poss[200100];
int f(int n)
{
if(uf[n]==n)
return n;
return uf[n]=f(uf[n]);
}
void u(int n,int m)
{
n=f(n);
m=f(m);
if(n==m)
return;
if(poss[n].size()<poss[m].size())
swap(n,m);
sum[n]+=sum[m];
int i;
for(i=0;i<poss[m].size();i++)
poss[n].push_back(poss[m][i]);
uf[m]=n;
}
vector<int>carry;
int arr[200100];
int ans[200100];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N,M;
cin >>N>>M;
int i;
for(i=0;i<N;i++)
cin >>arr[i+1];
for(i=0;i<M;i++)
{
int a,b;
cin >>a>>b;
link[a].push_back(b);
link[b].push_back(a);
x.push_back({a,b});
}
int summ=0;
vector<pair<int,int>>t;
for(i=0;i<N;i++)
{
summ+=arr[i+1];
t.push_back({arr[i+1],i+1});
carry.push_back(i+1);
}
memset(uf,-1,sizeof(uf));
sort(t.begin(),t.end());
for(i=0;i<t.size();i++)
{
uf[t[i].second]=t[i].second;
sum[t[i].second]=t[i].first;
poss[t[i].second].push_back(t[i].second);
int j;
for(j=0;j<link[t[i].second].size();j++)
{
if(uf[link[t[i].second][j]]>=0)
{
if(sum[f(link[t[i].second][j])]<t[i].first)
{
poss[f(link[t[i].second][j])].clear();
}
u(t[i].second,f(link[t[i].second][j]));
}
}
}
for(i=0;i<poss[f(1)].size();i++)
{
ans[poss[f(1)][i]]=1;
}
for(i=1;i<=N;i++)
cout <<ans[i];
}
Compilation message
island.cpp: In function 'void u(long long int, long long int)':
island.cpp:25:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(i=0;i<poss[m].size();i++)
| ~^~~~~~~~~~~~~~~
island.cpp: In function 'int main()':
island.cpp:59:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(i=0;i<t.size();i++)
| ~^~~~~~~~~
island.cpp:65:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(j=0;j<link[t[i].second].size();j++)
| ~^~~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:77:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(i=0;i<poss[f(1)].size();i++)
| ~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11212 KB |
Output is correct |
2 |
Correct |
6 ms |
11264 KB |
Output is correct |
3 |
Correct |
6 ms |
11220 KB |
Output is correct |
4 |
Correct |
8 ms |
11572 KB |
Output is correct |
5 |
Correct |
7 ms |
11604 KB |
Output is correct |
6 |
Correct |
8 ms |
11452 KB |
Output is correct |
7 |
Correct |
8 ms |
11476 KB |
Output is correct |
8 |
Correct |
7 ms |
11452 KB |
Output is correct |
9 |
Correct |
9 ms |
11604 KB |
Output is correct |
10 |
Correct |
8 ms |
11604 KB |
Output is correct |
11 |
Correct |
8 ms |
11536 KB |
Output is correct |
12 |
Correct |
8 ms |
11660 KB |
Output is correct |
13 |
Correct |
7 ms |
11540 KB |
Output is correct |
14 |
Correct |
7 ms |
11528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
11264 KB |
Output is correct |
2 |
Correct |
5 ms |
11220 KB |
Output is correct |
3 |
Correct |
163 ms |
40212 KB |
Output is correct |
4 |
Correct |
192 ms |
38200 KB |
Output is correct |
5 |
Correct |
224 ms |
42844 KB |
Output is correct |
6 |
Correct |
210 ms |
43884 KB |
Output is correct |
7 |
Correct |
212 ms |
43956 KB |
Output is correct |
8 |
Correct |
215 ms |
39780 KB |
Output is correct |
9 |
Correct |
167 ms |
46544 KB |
Output is correct |
10 |
Correct |
154 ms |
37284 KB |
Output is correct |
11 |
Correct |
171 ms |
40392 KB |
Output is correct |
12 |
Correct |
212 ms |
38680 KB |
Output is correct |
13 |
Correct |
176 ms |
37296 KB |
Output is correct |
14 |
Correct |
154 ms |
37432 KB |
Output is correct |
15 |
Correct |
152 ms |
38772 KB |
Output is correct |
16 |
Correct |
132 ms |
38472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11260 KB |
Output is correct |
2 |
Correct |
243 ms |
44592 KB |
Output is correct |
3 |
Correct |
232 ms |
44800 KB |
Output is correct |
4 |
Correct |
203 ms |
38800 KB |
Output is correct |
5 |
Correct |
198 ms |
37288 KB |
Output is correct |
6 |
Correct |
219 ms |
44564 KB |
Output is correct |
7 |
Correct |
164 ms |
38776 KB |
Output is correct |
8 |
Correct |
205 ms |
38892 KB |
Output is correct |
9 |
Correct |
104 ms |
38500 KB |
Output is correct |
10 |
Correct |
152 ms |
38044 KB |
Output is correct |
11 |
Correct |
198 ms |
37848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11264 KB |
Output is correct |
2 |
Correct |
238 ms |
40972 KB |
Output is correct |
3 |
Correct |
238 ms |
42100 KB |
Output is correct |
4 |
Correct |
258 ms |
44224 KB |
Output is correct |
5 |
Correct |
237 ms |
46376 KB |
Output is correct |
6 |
Correct |
211 ms |
41656 KB |
Output is correct |
7 |
Correct |
167 ms |
40428 KB |
Output is correct |
8 |
Correct |
103 ms |
39536 KB |
Output is correct |
9 |
Correct |
144 ms |
29688 KB |
Output is correct |
10 |
Correct |
284 ms |
46812 KB |
Output is correct |
11 |
Correct |
182 ms |
37792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11212 KB |
Output is correct |
2 |
Correct |
6 ms |
11264 KB |
Output is correct |
3 |
Correct |
6 ms |
11220 KB |
Output is correct |
4 |
Correct |
8 ms |
11572 KB |
Output is correct |
5 |
Correct |
7 ms |
11604 KB |
Output is correct |
6 |
Correct |
8 ms |
11452 KB |
Output is correct |
7 |
Correct |
8 ms |
11476 KB |
Output is correct |
8 |
Correct |
7 ms |
11452 KB |
Output is correct |
9 |
Correct |
9 ms |
11604 KB |
Output is correct |
10 |
Correct |
8 ms |
11604 KB |
Output is correct |
11 |
Correct |
8 ms |
11536 KB |
Output is correct |
12 |
Correct |
8 ms |
11660 KB |
Output is correct |
13 |
Correct |
7 ms |
11540 KB |
Output is correct |
14 |
Correct |
7 ms |
11528 KB |
Output is correct |
15 |
Correct |
5 ms |
11264 KB |
Output is correct |
16 |
Correct |
5 ms |
11220 KB |
Output is correct |
17 |
Correct |
163 ms |
40212 KB |
Output is correct |
18 |
Correct |
192 ms |
38200 KB |
Output is correct |
19 |
Correct |
224 ms |
42844 KB |
Output is correct |
20 |
Correct |
210 ms |
43884 KB |
Output is correct |
21 |
Correct |
212 ms |
43956 KB |
Output is correct |
22 |
Correct |
215 ms |
39780 KB |
Output is correct |
23 |
Correct |
167 ms |
46544 KB |
Output is correct |
24 |
Correct |
154 ms |
37284 KB |
Output is correct |
25 |
Correct |
171 ms |
40392 KB |
Output is correct |
26 |
Correct |
212 ms |
38680 KB |
Output is correct |
27 |
Correct |
176 ms |
37296 KB |
Output is correct |
28 |
Correct |
154 ms |
37432 KB |
Output is correct |
29 |
Correct |
152 ms |
38772 KB |
Output is correct |
30 |
Correct |
132 ms |
38472 KB |
Output is correct |
31 |
Correct |
6 ms |
11260 KB |
Output is correct |
32 |
Correct |
243 ms |
44592 KB |
Output is correct |
33 |
Correct |
232 ms |
44800 KB |
Output is correct |
34 |
Correct |
203 ms |
38800 KB |
Output is correct |
35 |
Correct |
198 ms |
37288 KB |
Output is correct |
36 |
Correct |
219 ms |
44564 KB |
Output is correct |
37 |
Correct |
164 ms |
38776 KB |
Output is correct |
38 |
Correct |
205 ms |
38892 KB |
Output is correct |
39 |
Correct |
104 ms |
38500 KB |
Output is correct |
40 |
Correct |
152 ms |
38044 KB |
Output is correct |
41 |
Correct |
198 ms |
37848 KB |
Output is correct |
42 |
Correct |
7 ms |
11264 KB |
Output is correct |
43 |
Correct |
238 ms |
40972 KB |
Output is correct |
44 |
Correct |
238 ms |
42100 KB |
Output is correct |
45 |
Correct |
258 ms |
44224 KB |
Output is correct |
46 |
Correct |
237 ms |
46376 KB |
Output is correct |
47 |
Correct |
211 ms |
41656 KB |
Output is correct |
48 |
Correct |
167 ms |
40428 KB |
Output is correct |
49 |
Correct |
103 ms |
39536 KB |
Output is correct |
50 |
Correct |
144 ms |
29688 KB |
Output is correct |
51 |
Correct |
284 ms |
46812 KB |
Output is correct |
52 |
Correct |
182 ms |
37792 KB |
Output is correct |
53 |
Correct |
7 ms |
11264 KB |
Output is correct |
54 |
Correct |
6 ms |
11220 KB |
Output is correct |
55 |
Correct |
7 ms |
11220 KB |
Output is correct |
56 |
Correct |
7 ms |
11476 KB |
Output is correct |
57 |
Correct |
8 ms |
11528 KB |
Output is correct |
58 |
Correct |
7 ms |
11532 KB |
Output is correct |
59 |
Correct |
7 ms |
11476 KB |
Output is correct |
60 |
Correct |
6 ms |
11484 KB |
Output is correct |
61 |
Correct |
7 ms |
11604 KB |
Output is correct |
62 |
Correct |
7 ms |
11604 KB |
Output is correct |
63 |
Correct |
7 ms |
11576 KB |
Output is correct |
64 |
Correct |
7 ms |
11604 KB |
Output is correct |
65 |
Correct |
9 ms |
11476 KB |
Output is correct |
66 |
Correct |
9 ms |
11524 KB |
Output is correct |
67 |
Correct |
180 ms |
40256 KB |
Output is correct |
68 |
Correct |
167 ms |
38284 KB |
Output is correct |
69 |
Correct |
211 ms |
42776 KB |
Output is correct |
70 |
Correct |
231 ms |
43848 KB |
Output is correct |
71 |
Correct |
207 ms |
43860 KB |
Output is correct |
72 |
Correct |
205 ms |
39788 KB |
Output is correct |
73 |
Correct |
196 ms |
46524 KB |
Output is correct |
74 |
Correct |
142 ms |
37216 KB |
Output is correct |
75 |
Correct |
154 ms |
40388 KB |
Output is correct |
76 |
Correct |
208 ms |
38712 KB |
Output is correct |
77 |
Correct |
148 ms |
37184 KB |
Output is correct |
78 |
Correct |
151 ms |
37460 KB |
Output is correct |
79 |
Correct |
180 ms |
38752 KB |
Output is correct |
80 |
Correct |
105 ms |
38512 KB |
Output is correct |
81 |
Correct |
247 ms |
44656 KB |
Output is correct |
82 |
Correct |
249 ms |
44908 KB |
Output is correct |
83 |
Correct |
199 ms |
38588 KB |
Output is correct |
84 |
Correct |
147 ms |
37300 KB |
Output is correct |
85 |
Correct |
271 ms |
44468 KB |
Output is correct |
86 |
Correct |
197 ms |
38856 KB |
Output is correct |
87 |
Correct |
181 ms |
38768 KB |
Output is correct |
88 |
Correct |
164 ms |
37976 KB |
Output is correct |
89 |
Correct |
186 ms |
37840 KB |
Output is correct |
90 |
Correct |
242 ms |
41004 KB |
Output is correct |
91 |
Correct |
276 ms |
42016 KB |
Output is correct |
92 |
Correct |
260 ms |
44384 KB |
Output is correct |
93 |
Correct |
226 ms |
46580 KB |
Output is correct |
94 |
Correct |
254 ms |
41676 KB |
Output is correct |
95 |
Correct |
185 ms |
40420 KB |
Output is correct |
96 |
Correct |
119 ms |
39648 KB |
Output is correct |
97 |
Correct |
151 ms |
29668 KB |
Output is correct |
98 |
Correct |
217 ms |
46796 KB |
Output is correct |
99 |
Correct |
219 ms |
37756 KB |
Output is correct |
100 |
Correct |
56 ms |
19376 KB |
Output is correct |
101 |
Correct |
297 ms |
42752 KB |
Output is correct |
102 |
Correct |
222 ms |
36956 KB |
Output is correct |
103 |
Correct |
226 ms |
36240 KB |
Output is correct |
104 |
Correct |
292 ms |
40052 KB |
Output is correct |