#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const long long mxn = 1e6 + 10;
struct we
{
long long idx,val;
};
bool cmp(const struct we &l,const struct we &r)
{
return l.val < r.val;
}
struct we sot[mxn] = {};
char ans[mxn] = {};
long long npop[mxn] = {},gr[mxn] = {},he[mxn] = {},siz[mxn] = {},u[mxn] = {};
vector<long long> pat[mxn] = {},tre[mxn] = {};
long long figr(long long l)
{
long long cl = l,f;
while(l != gr[l])
{
l = gr[l];
}
while(cl != gr[cl])
{
f = gr[cl];
gr[cl] = l;
cl = f;
}
return l;
}
long long mer(long long cl,long long cr)
{
long long l = figr(cl),r = figr(cr);
gr[r] = l;
siz[l] += siz[r];
return l;
}
long long re(long long cn)
{
long long i,j,fn;
ans[cn] = '1';
for(i=0; i<tre[cn].size(); i++)
{
fn = tre[cn][i];
re(fn);
}
return 0;
}
int main()
{
long long i,j,n,m,cn,cm,fn,fm;
scanf("%lld %lld",&n,&m);
for(i=0; i<n; i++)
{
scanf("%lld",&npop[i]);
sot[i] = {i,npop[i]};
he[i] = i;
gr[i] = i;
siz[i] = npop[i];
ans[i] = '0';
}
for(i=0; i<m; i++)
{
scanf("%lld %lld",&cn,&cm);
pat[cn-1].push_back(cm-1);
pat[cm-1].push_back(cn-1);
}
sort(sot,sot+n,cmp);
for(i=0; i<n; i++)
{
cn = sot[i].idx;
u[cn] = 1;
for(j=0; j<pat[cn].size(); j++)
{
fn = pat[cn][j];
if(u[fn] == 0)
{
continue;
}
cm = figr(cn);
fm = figr(fn);
if(cm != fm)
{
if(siz[fm] >= npop[cn])
{
tre[cn].push_back(he[fm]);
}
mer(cm,fm);
}
}
}
re(sot[n-1].idx);
printf("%s\n",ans);
return 0;
}
Compilation message
island.cpp: In function 'long long int re(long long int)':
island.cpp:46:15: 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]
46 | for(i=0; i<tre[cn].size(); i++)
| ~^~~~~~~~~~~~~~~
island.cpp:44:17: warning: unused variable 'j' [-Wunused-variable]
44 | long long i,j,fn;
| ^
island.cpp: In function 'int main()':
island.cpp:77:19: 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(j=0; j<pat[cn].size(); j++)
| ~^~~~~~~~~~~~~~~
island.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%lld %lld",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~~~~~
island.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%lld",&npop[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
island.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | scanf("%lld %lld",&cn,&cm);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47324 KB |
Output is correct |
2 |
Correct |
21 ms |
47216 KB |
Output is correct |
3 |
Correct |
20 ms |
47308 KB |
Output is correct |
4 |
Correct |
21 ms |
47444 KB |
Output is correct |
5 |
Correct |
22 ms |
47476 KB |
Output is correct |
6 |
Correct |
22 ms |
47544 KB |
Output is correct |
7 |
Correct |
23 ms |
47444 KB |
Output is correct |
8 |
Correct |
22 ms |
47436 KB |
Output is correct |
9 |
Correct |
22 ms |
47564 KB |
Output is correct |
10 |
Correct |
28 ms |
47472 KB |
Output is correct |
11 |
Correct |
23 ms |
47436 KB |
Output is correct |
12 |
Correct |
22 ms |
47528 KB |
Output is correct |
13 |
Correct |
21 ms |
47536 KB |
Output is correct |
14 |
Correct |
21 ms |
47444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47240 KB |
Output is correct |
2 |
Correct |
20 ms |
47200 KB |
Output is correct |
3 |
Correct |
141 ms |
70668 KB |
Output is correct |
4 |
Correct |
155 ms |
71780 KB |
Output is correct |
5 |
Correct |
142 ms |
72052 KB |
Output is correct |
6 |
Correct |
140 ms |
72928 KB |
Output is correct |
7 |
Correct |
147 ms |
72884 KB |
Output is correct |
8 |
Correct |
158 ms |
74800 KB |
Output is correct |
9 |
Correct |
127 ms |
72152 KB |
Output is correct |
10 |
Correct |
104 ms |
70096 KB |
Output is correct |
11 |
Correct |
110 ms |
72728 KB |
Output is correct |
12 |
Correct |
141 ms |
72748 KB |
Output is correct |
13 |
Correct |
119 ms |
73660 KB |
Output is correct |
14 |
Correct |
151 ms |
73784 KB |
Output is correct |
15 |
Correct |
125 ms |
79008 KB |
Output is correct |
16 |
Correct |
126 ms |
78100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47308 KB |
Output is correct |
2 |
Correct |
162 ms |
67228 KB |
Output is correct |
3 |
Correct |
187 ms |
71740 KB |
Output is correct |
4 |
Correct |
129 ms |
75212 KB |
Output is correct |
5 |
Correct |
134 ms |
73536 KB |
Output is correct |
6 |
Correct |
169 ms |
71744 KB |
Output is correct |
7 |
Correct |
149 ms |
79064 KB |
Output is correct |
8 |
Correct |
176 ms |
79072 KB |
Output is correct |
9 |
Correct |
102 ms |
77988 KB |
Output is correct |
10 |
Correct |
123 ms |
71636 KB |
Output is correct |
11 |
Correct |
128 ms |
71140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47252 KB |
Output is correct |
2 |
Correct |
199 ms |
68796 KB |
Output is correct |
3 |
Correct |
171 ms |
73088 KB |
Output is correct |
4 |
Correct |
181 ms |
73472 KB |
Output is correct |
5 |
Correct |
156 ms |
74432 KB |
Output is correct |
6 |
Correct |
154 ms |
73800 KB |
Output is correct |
7 |
Correct |
123 ms |
73880 KB |
Output is correct |
8 |
Correct |
112 ms |
77452 KB |
Output is correct |
9 |
Correct |
136 ms |
63756 KB |
Output is correct |
10 |
Correct |
139 ms |
73012 KB |
Output is correct |
11 |
Correct |
135 ms |
71116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
47324 KB |
Output is correct |
2 |
Correct |
21 ms |
47216 KB |
Output is correct |
3 |
Correct |
20 ms |
47308 KB |
Output is correct |
4 |
Correct |
21 ms |
47444 KB |
Output is correct |
5 |
Correct |
22 ms |
47476 KB |
Output is correct |
6 |
Correct |
22 ms |
47544 KB |
Output is correct |
7 |
Correct |
23 ms |
47444 KB |
Output is correct |
8 |
Correct |
22 ms |
47436 KB |
Output is correct |
9 |
Correct |
22 ms |
47564 KB |
Output is correct |
10 |
Correct |
28 ms |
47472 KB |
Output is correct |
11 |
Correct |
23 ms |
47436 KB |
Output is correct |
12 |
Correct |
22 ms |
47528 KB |
Output is correct |
13 |
Correct |
21 ms |
47536 KB |
Output is correct |
14 |
Correct |
21 ms |
47444 KB |
Output is correct |
15 |
Correct |
21 ms |
47240 KB |
Output is correct |
16 |
Correct |
20 ms |
47200 KB |
Output is correct |
17 |
Correct |
141 ms |
70668 KB |
Output is correct |
18 |
Correct |
155 ms |
71780 KB |
Output is correct |
19 |
Correct |
142 ms |
72052 KB |
Output is correct |
20 |
Correct |
140 ms |
72928 KB |
Output is correct |
21 |
Correct |
147 ms |
72884 KB |
Output is correct |
22 |
Correct |
158 ms |
74800 KB |
Output is correct |
23 |
Correct |
127 ms |
72152 KB |
Output is correct |
24 |
Correct |
104 ms |
70096 KB |
Output is correct |
25 |
Correct |
110 ms |
72728 KB |
Output is correct |
26 |
Correct |
141 ms |
72748 KB |
Output is correct |
27 |
Correct |
119 ms |
73660 KB |
Output is correct |
28 |
Correct |
151 ms |
73784 KB |
Output is correct |
29 |
Correct |
125 ms |
79008 KB |
Output is correct |
30 |
Correct |
126 ms |
78100 KB |
Output is correct |
31 |
Correct |
21 ms |
47308 KB |
Output is correct |
32 |
Correct |
162 ms |
67228 KB |
Output is correct |
33 |
Correct |
187 ms |
71740 KB |
Output is correct |
34 |
Correct |
129 ms |
75212 KB |
Output is correct |
35 |
Correct |
134 ms |
73536 KB |
Output is correct |
36 |
Correct |
169 ms |
71744 KB |
Output is correct |
37 |
Correct |
149 ms |
79064 KB |
Output is correct |
38 |
Correct |
176 ms |
79072 KB |
Output is correct |
39 |
Correct |
102 ms |
77988 KB |
Output is correct |
40 |
Correct |
123 ms |
71636 KB |
Output is correct |
41 |
Correct |
128 ms |
71140 KB |
Output is correct |
42 |
Correct |
21 ms |
47252 KB |
Output is correct |
43 |
Correct |
199 ms |
68796 KB |
Output is correct |
44 |
Correct |
171 ms |
73088 KB |
Output is correct |
45 |
Correct |
181 ms |
73472 KB |
Output is correct |
46 |
Correct |
156 ms |
74432 KB |
Output is correct |
47 |
Correct |
154 ms |
73800 KB |
Output is correct |
48 |
Correct |
123 ms |
73880 KB |
Output is correct |
49 |
Correct |
112 ms |
77452 KB |
Output is correct |
50 |
Correct |
136 ms |
63756 KB |
Output is correct |
51 |
Correct |
139 ms |
73012 KB |
Output is correct |
52 |
Correct |
135 ms |
71116 KB |
Output is correct |
53 |
Correct |
21 ms |
47316 KB |
Output is correct |
54 |
Correct |
21 ms |
47272 KB |
Output is correct |
55 |
Correct |
20 ms |
47264 KB |
Output is correct |
56 |
Correct |
22 ms |
47444 KB |
Output is correct |
57 |
Correct |
22 ms |
47536 KB |
Output is correct |
58 |
Correct |
22 ms |
47444 KB |
Output is correct |
59 |
Correct |
22 ms |
47548 KB |
Output is correct |
60 |
Correct |
23 ms |
47416 KB |
Output is correct |
61 |
Correct |
22 ms |
47540 KB |
Output is correct |
62 |
Correct |
22 ms |
47436 KB |
Output is correct |
63 |
Correct |
22 ms |
47444 KB |
Output is correct |
64 |
Correct |
22 ms |
47544 KB |
Output is correct |
65 |
Correct |
21 ms |
47536 KB |
Output is correct |
66 |
Correct |
24 ms |
47444 KB |
Output is correct |
67 |
Correct |
128 ms |
75056 KB |
Output is correct |
68 |
Correct |
131 ms |
74292 KB |
Output is correct |
69 |
Correct |
135 ms |
72084 KB |
Output is correct |
70 |
Correct |
134 ms |
72852 KB |
Output is correct |
71 |
Correct |
143 ms |
72912 KB |
Output is correct |
72 |
Correct |
146 ms |
74820 KB |
Output is correct |
73 |
Correct |
125 ms |
72144 KB |
Output is correct |
74 |
Correct |
102 ms |
70000 KB |
Output is correct |
75 |
Correct |
105 ms |
72760 KB |
Output is correct |
76 |
Correct |
133 ms |
72696 KB |
Output is correct |
77 |
Correct |
132 ms |
73548 KB |
Output is correct |
78 |
Correct |
135 ms |
73848 KB |
Output is correct |
79 |
Correct |
127 ms |
79024 KB |
Output is correct |
80 |
Correct |
105 ms |
78056 KB |
Output is correct |
81 |
Correct |
158 ms |
71632 KB |
Output is correct |
82 |
Correct |
164 ms |
71688 KB |
Output is correct |
83 |
Correct |
148 ms |
75252 KB |
Output is correct |
84 |
Correct |
126 ms |
73652 KB |
Output is correct |
85 |
Correct |
161 ms |
71696 KB |
Output is correct |
86 |
Correct |
168 ms |
79048 KB |
Output is correct |
87 |
Correct |
151 ms |
79044 KB |
Output is correct |
88 |
Correct |
125 ms |
71596 KB |
Output is correct |
89 |
Correct |
145 ms |
71112 KB |
Output is correct |
90 |
Correct |
178 ms |
73184 KB |
Output is correct |
91 |
Correct |
174 ms |
72956 KB |
Output is correct |
92 |
Correct |
179 ms |
73384 KB |
Output is correct |
93 |
Correct |
171 ms |
74432 KB |
Output is correct |
94 |
Correct |
159 ms |
73852 KB |
Output is correct |
95 |
Correct |
113 ms |
73632 KB |
Output is correct |
96 |
Correct |
114 ms |
77484 KB |
Output is correct |
97 |
Correct |
112 ms |
63740 KB |
Output is correct |
98 |
Correct |
160 ms |
72912 KB |
Output is correct |
99 |
Correct |
134 ms |
71104 KB |
Output is correct |
100 |
Correct |
60 ms |
53896 KB |
Output is correct |
101 |
Correct |
179 ms |
72868 KB |
Output is correct |
102 |
Correct |
164 ms |
70980 KB |
Output is correct |
103 |
Correct |
189 ms |
70976 KB |
Output is correct |
104 |
Correct |
190 ms |
72876 KB |
Output is correct |