#include <bits/stdc++.h>
#define MAX 205000
using ll = long long;
ll array[MAX];
ll pai[MAX];
ll size[MAX];
int find(int a){
if(pai[a]==a)
return a;
return pai[a]=find(pai[a]);
}
void Union(int a,int b){
a=find(a);
b=find(b);
if(a!=b){
pai[a]=b;
size[b]+=size[a];
size[a]=0;
}
}
bool answer[MAX];
typedef std::pair<ll,ll> pii;
std::map<ll,std::vector<pii>> eventos;
int main()
{
for(int i=0;i!=MAX;++i)pai[i]=i;
int N,M;
std::cin>>N>>M;
///Corner case...
if(N==1){
std::cout<<"1\n";
return 0;
}
for(int i=0;i!=N;++i){
std::cin>>array[i];
eventos[array[i]].push_back({1e9+1,i});
size[i]=array[i];
}
ll soma = 0;
for(auto&x:array)soma+=x;
for(int i=0;i!=M;++i){
int a,b;
std::cin>>a>>b;--a;--b;
int peso = std::max(array[a],array[b]);
eventos[peso].push_back({a,b});
}
for(auto&x:eventos){
std::sort(x.second.begin(),x.second.end());
for(auto&y:x.second){
if(y.first==1e9+1){///Consulta
ll k = find(y.second);
ll sum = size[k];
///Ve se aumentou
if(sum!=x.first){
///Sucesso
if(sum==soma){
answer[y.second]=true;
}else ///Ainda falta...
eventos[sum].push_back(y);
}
}else {///Unir :v
Union(y.first,y.second);
}
}
}
for(int i=0;i!=N;++i)std::cout<<"01"[answer[i]];std::cout<<"\n";
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:80:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
80 | for(int i=0;i!=N;++i)std::cout<<"01"[answer[i]];std::cout<<"\n";
| ^~~
island.cpp:80:53: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
80 | for(int i=0;i!=N;++i)std::cout<<"01"[answer[i]];std::cout<<"\n";
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
4 ms |
2324 KB |
Output is correct |
5 |
Correct |
4 ms |
2260 KB |
Output is correct |
6 |
Correct |
3 ms |
2004 KB |
Output is correct |
7 |
Correct |
4 ms |
2260 KB |
Output is correct |
8 |
Correct |
4 ms |
2132 KB |
Output is correct |
9 |
Correct |
3 ms |
2004 KB |
Output is correct |
10 |
Correct |
4 ms |
2260 KB |
Output is correct |
11 |
Correct |
4 ms |
2316 KB |
Output is correct |
12 |
Correct |
4 ms |
2260 KB |
Output is correct |
13 |
Correct |
3 ms |
2132 KB |
Output is correct |
14 |
Correct |
3 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
533 ms |
49312 KB |
Output is correct |
4 |
Correct |
190 ms |
20788 KB |
Output is correct |
5 |
Correct |
567 ms |
45900 KB |
Output is correct |
6 |
Correct |
503 ms |
43116 KB |
Output is correct |
7 |
Correct |
589 ms |
48672 KB |
Output is correct |
8 |
Correct |
246 ms |
21544 KB |
Output is correct |
9 |
Correct |
419 ms |
41232 KB |
Output is correct |
10 |
Correct |
220 ms |
30392 KB |
Output is correct |
11 |
Correct |
206 ms |
15960 KB |
Output is correct |
12 |
Correct |
201 ms |
17316 KB |
Output is correct |
13 |
Correct |
183 ms |
21412 KB |
Output is correct |
14 |
Correct |
201 ms |
21924 KB |
Output is correct |
15 |
Correct |
544 ms |
56072 KB |
Output is correct |
16 |
Correct |
330 ms |
55264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
768 ms |
50344 KB |
Output is correct |
3 |
Correct |
727 ms |
45144 KB |
Output is correct |
4 |
Correct |
229 ms |
15196 KB |
Output is correct |
5 |
Correct |
193 ms |
20108 KB |
Output is correct |
6 |
Correct |
729 ms |
49512 KB |
Output is correct |
7 |
Correct |
589 ms |
56012 KB |
Output is correct |
8 |
Correct |
574 ms |
55796 KB |
Output is correct |
9 |
Correct |
337 ms |
54308 KB |
Output is correct |
10 |
Correct |
266 ms |
27624 KB |
Output is correct |
11 |
Correct |
252 ms |
20848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
253 ms |
17680 KB |
Output is correct |
3 |
Correct |
282 ms |
18972 KB |
Output is correct |
4 |
Correct |
260 ms |
17420 KB |
Output is correct |
5 |
Correct |
228 ms |
16176 KB |
Output is correct |
6 |
Correct |
229 ms |
15948 KB |
Output is correct |
7 |
Correct |
258 ms |
21616 KB |
Output is correct |
8 |
Correct |
214 ms |
21636 KB |
Output is correct |
9 |
Correct |
165 ms |
12976 KB |
Output is correct |
10 |
Correct |
230 ms |
20156 KB |
Output is correct |
11 |
Correct |
205 ms |
18592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
4 ms |
2324 KB |
Output is correct |
5 |
Correct |
4 ms |
2260 KB |
Output is correct |
6 |
Correct |
3 ms |
2004 KB |
Output is correct |
7 |
Correct |
4 ms |
2260 KB |
Output is correct |
8 |
Correct |
4 ms |
2132 KB |
Output is correct |
9 |
Correct |
3 ms |
2004 KB |
Output is correct |
10 |
Correct |
4 ms |
2260 KB |
Output is correct |
11 |
Correct |
4 ms |
2316 KB |
Output is correct |
12 |
Correct |
4 ms |
2260 KB |
Output is correct |
13 |
Correct |
3 ms |
2132 KB |
Output is correct |
14 |
Correct |
3 ms |
2132 KB |
Output is correct |
15 |
Correct |
2 ms |
1876 KB |
Output is correct |
16 |
Correct |
1 ms |
1876 KB |
Output is correct |
17 |
Correct |
533 ms |
49312 KB |
Output is correct |
18 |
Correct |
190 ms |
20788 KB |
Output is correct |
19 |
Correct |
567 ms |
45900 KB |
Output is correct |
20 |
Correct |
503 ms |
43116 KB |
Output is correct |
21 |
Correct |
589 ms |
48672 KB |
Output is correct |
22 |
Correct |
246 ms |
21544 KB |
Output is correct |
23 |
Correct |
419 ms |
41232 KB |
Output is correct |
24 |
Correct |
220 ms |
30392 KB |
Output is correct |
25 |
Correct |
206 ms |
15960 KB |
Output is correct |
26 |
Correct |
201 ms |
17316 KB |
Output is correct |
27 |
Correct |
183 ms |
21412 KB |
Output is correct |
28 |
Correct |
201 ms |
21924 KB |
Output is correct |
29 |
Correct |
544 ms |
56072 KB |
Output is correct |
30 |
Correct |
330 ms |
55264 KB |
Output is correct |
31 |
Correct |
1 ms |
1876 KB |
Output is correct |
32 |
Correct |
768 ms |
50344 KB |
Output is correct |
33 |
Correct |
727 ms |
45144 KB |
Output is correct |
34 |
Correct |
229 ms |
15196 KB |
Output is correct |
35 |
Correct |
193 ms |
20108 KB |
Output is correct |
36 |
Correct |
729 ms |
49512 KB |
Output is correct |
37 |
Correct |
589 ms |
56012 KB |
Output is correct |
38 |
Correct |
574 ms |
55796 KB |
Output is correct |
39 |
Correct |
337 ms |
54308 KB |
Output is correct |
40 |
Correct |
266 ms |
27624 KB |
Output is correct |
41 |
Correct |
252 ms |
20848 KB |
Output is correct |
42 |
Correct |
1 ms |
1876 KB |
Output is correct |
43 |
Correct |
253 ms |
17680 KB |
Output is correct |
44 |
Correct |
282 ms |
18972 KB |
Output is correct |
45 |
Correct |
260 ms |
17420 KB |
Output is correct |
46 |
Correct |
228 ms |
16176 KB |
Output is correct |
47 |
Correct |
229 ms |
15948 KB |
Output is correct |
48 |
Correct |
258 ms |
21616 KB |
Output is correct |
49 |
Correct |
214 ms |
21636 KB |
Output is correct |
50 |
Correct |
165 ms |
12976 KB |
Output is correct |
51 |
Correct |
230 ms |
20156 KB |
Output is correct |
52 |
Correct |
205 ms |
18592 KB |
Output is correct |
53 |
Correct |
1 ms |
1876 KB |
Output is correct |
54 |
Correct |
2 ms |
1876 KB |
Output is correct |
55 |
Correct |
1 ms |
1876 KB |
Output is correct |
56 |
Correct |
5 ms |
2260 KB |
Output is correct |
57 |
Correct |
5 ms |
2260 KB |
Output is correct |
58 |
Correct |
3 ms |
2028 KB |
Output is correct |
59 |
Correct |
4 ms |
2260 KB |
Output is correct |
60 |
Correct |
5 ms |
2260 KB |
Output is correct |
61 |
Correct |
3 ms |
2060 KB |
Output is correct |
62 |
Correct |
4 ms |
2260 KB |
Output is correct |
63 |
Correct |
4 ms |
2332 KB |
Output is correct |
64 |
Correct |
4 ms |
2232 KB |
Output is correct |
65 |
Correct |
3 ms |
2132 KB |
Output is correct |
66 |
Correct |
3 ms |
2004 KB |
Output is correct |
67 |
Correct |
574 ms |
50032 KB |
Output is correct |
68 |
Correct |
190 ms |
21028 KB |
Output is correct |
69 |
Correct |
575 ms |
45364 KB |
Output is correct |
70 |
Correct |
544 ms |
43192 KB |
Output is correct |
71 |
Correct |
557 ms |
47180 KB |
Output is correct |
72 |
Correct |
249 ms |
21172 KB |
Output is correct |
73 |
Correct |
417 ms |
41204 KB |
Output is correct |
74 |
Correct |
245 ms |
28540 KB |
Output is correct |
75 |
Correct |
201 ms |
14680 KB |
Output is correct |
76 |
Correct |
202 ms |
16676 KB |
Output is correct |
77 |
Correct |
188 ms |
21292 KB |
Output is correct |
78 |
Correct |
197 ms |
20796 KB |
Output is correct |
79 |
Correct |
563 ms |
54864 KB |
Output is correct |
80 |
Correct |
323 ms |
56184 KB |
Output is correct |
81 |
Correct |
763 ms |
49320 KB |
Output is correct |
82 |
Correct |
644 ms |
45528 KB |
Output is correct |
83 |
Correct |
239 ms |
13392 KB |
Output is correct |
84 |
Correct |
186 ms |
20936 KB |
Output is correct |
85 |
Correct |
748 ms |
51652 KB |
Output is correct |
86 |
Correct |
557 ms |
58120 KB |
Output is correct |
87 |
Correct |
586 ms |
57988 KB |
Output is correct |
88 |
Correct |
282 ms |
26988 KB |
Output is correct |
89 |
Correct |
215 ms |
18576 KB |
Output is correct |
90 |
Correct |
266 ms |
18224 KB |
Output is correct |
91 |
Correct |
273 ms |
20308 KB |
Output is correct |
92 |
Correct |
273 ms |
20428 KB |
Output is correct |
93 |
Correct |
237 ms |
16212 KB |
Output is correct |
94 |
Correct |
219 ms |
15336 KB |
Output is correct |
95 |
Correct |
246 ms |
23568 KB |
Output is correct |
96 |
Correct |
189 ms |
21208 KB |
Output is correct |
97 |
Correct |
164 ms |
13316 KB |
Output is correct |
98 |
Correct |
205 ms |
21668 KB |
Output is correct |
99 |
Correct |
205 ms |
20008 KB |
Output is correct |
100 |
Correct |
123 ms |
9324 KB |
Output is correct |
101 |
Correct |
638 ms |
45732 KB |
Output is correct |
102 |
Correct |
217 ms |
15224 KB |
Output is correct |
103 |
Correct |
543 ms |
35144 KB |
Output is correct |
104 |
Correct |
712 ms |
46012 KB |
Output is correct |