#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N=2e5+10;
int n, m, c[N], par[N];
vi ad[N], ok[N];
map<int, vi> col;
set<int> dif;
bool can[N];
ll sm[N];
int fnd(int u)
{
return par[u]=par[u]==u?u:fnd(par[u]);
}
void mrg(int a, int b)
{
a=fnd(a); b=fnd(b);
if(a==b) return;
if(sz(ok[a])>sz(ok[b])) ok[a].swap(ok[b]);
for(auto x : ok[a]) ok[b].pb(x);
sm[b]+=sm[a];
par[a]=b;
}
int main()
{
setIO();
cin >> n >> m;
FOR(i, 0, n) cin >> c[i], dif.insert(c[i]), col[c[i]].pb(i), par[i]=i, ok[i].pb(i), can[i]=true, sm[i]=c[i];
FOR(i, 0, m)
{
int a, b;
cin >> a >> b;
ad[a-1].pb(b-1);
ad[b-1].pb(a-1);
}
for(auto val : dif){
for(auto i : col[val]){
for(auto x : ad[i]){
if(c[x]>c[i]) continue;
x=fnd(x);
if(sm[x]<c[i]){
while(sz(ok[x])){
can[ok[x].back()]=false;
ok[x].pop_back();
}
}
mrg(i, x);
}
}
}
FOR(i, 0, n) cout << can[i];
}
Compilation message
island.cpp: In function 'void setIO(std::string)':
island.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
10 ms |
10060 KB |
Output is correct |
5 |
Correct |
8 ms |
10068 KB |
Output is correct |
6 |
Correct |
7 ms |
9812 KB |
Output is correct |
7 |
Correct |
8 ms |
10068 KB |
Output is correct |
8 |
Correct |
7 ms |
10068 KB |
Output is correct |
9 |
Correct |
6 ms |
9812 KB |
Output is correct |
10 |
Correct |
8 ms |
10068 KB |
Output is correct |
11 |
Correct |
8 ms |
10196 KB |
Output is correct |
12 |
Correct |
8 ms |
10068 KB |
Output is correct |
13 |
Correct |
8 ms |
9812 KB |
Output is correct |
14 |
Correct |
7 ms |
9940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9656 KB |
Output is correct |
2 |
Correct |
8 ms |
9684 KB |
Output is correct |
3 |
Correct |
308 ms |
58040 KB |
Output is correct |
4 |
Correct |
151 ms |
27872 KB |
Output is correct |
5 |
Correct |
384 ms |
58276 KB |
Output is correct |
6 |
Correct |
341 ms |
52360 KB |
Output is correct |
7 |
Correct |
382 ms |
59852 KB |
Output is correct |
8 |
Correct |
219 ms |
28068 KB |
Output is correct |
9 |
Correct |
285 ms |
53832 KB |
Output is correct |
10 |
Correct |
284 ms |
50348 KB |
Output is correct |
11 |
Correct |
183 ms |
30160 KB |
Output is correct |
12 |
Correct |
217 ms |
27684 KB |
Output is correct |
13 |
Correct |
160 ms |
28824 KB |
Output is correct |
14 |
Correct |
149 ms |
28740 KB |
Output is correct |
15 |
Correct |
274 ms |
57960 KB |
Output is correct |
16 |
Correct |
280 ms |
57444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
604 ms |
60532 KB |
Output is correct |
3 |
Correct |
514 ms |
53400 KB |
Output is correct |
4 |
Correct |
153 ms |
27840 KB |
Output is correct |
5 |
Correct |
154 ms |
28040 KB |
Output is correct |
6 |
Correct |
581 ms |
60764 KB |
Output is correct |
7 |
Correct |
289 ms |
57948 KB |
Output is correct |
8 |
Correct |
296 ms |
57936 KB |
Output is correct |
9 |
Correct |
226 ms |
57484 KB |
Output is correct |
10 |
Correct |
264 ms |
42896 KB |
Output is correct |
11 |
Correct |
172 ms |
29108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
219 ms |
28232 KB |
Output is correct |
3 |
Correct |
253 ms |
28692 KB |
Output is correct |
4 |
Correct |
276 ms |
29644 KB |
Output is correct |
5 |
Correct |
244 ms |
30964 KB |
Output is correct |
6 |
Correct |
211 ms |
28696 KB |
Output is correct |
7 |
Correct |
179 ms |
29256 KB |
Output is correct |
8 |
Correct |
121 ms |
28656 KB |
Output is correct |
9 |
Correct |
114 ms |
19936 KB |
Output is correct |
10 |
Correct |
273 ms |
32468 KB |
Output is correct |
11 |
Correct |
170 ms |
27804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
4 |
Correct |
10 ms |
10060 KB |
Output is correct |
5 |
Correct |
8 ms |
10068 KB |
Output is correct |
6 |
Correct |
7 ms |
9812 KB |
Output is correct |
7 |
Correct |
8 ms |
10068 KB |
Output is correct |
8 |
Correct |
7 ms |
10068 KB |
Output is correct |
9 |
Correct |
6 ms |
9812 KB |
Output is correct |
10 |
Correct |
8 ms |
10068 KB |
Output is correct |
11 |
Correct |
8 ms |
10196 KB |
Output is correct |
12 |
Correct |
8 ms |
10068 KB |
Output is correct |
13 |
Correct |
8 ms |
9812 KB |
Output is correct |
14 |
Correct |
7 ms |
9940 KB |
Output is correct |
15 |
Correct |
6 ms |
9656 KB |
Output is correct |
16 |
Correct |
8 ms |
9684 KB |
Output is correct |
17 |
Correct |
308 ms |
58040 KB |
Output is correct |
18 |
Correct |
151 ms |
27872 KB |
Output is correct |
19 |
Correct |
384 ms |
58276 KB |
Output is correct |
20 |
Correct |
341 ms |
52360 KB |
Output is correct |
21 |
Correct |
382 ms |
59852 KB |
Output is correct |
22 |
Correct |
219 ms |
28068 KB |
Output is correct |
23 |
Correct |
285 ms |
53832 KB |
Output is correct |
24 |
Correct |
284 ms |
50348 KB |
Output is correct |
25 |
Correct |
183 ms |
30160 KB |
Output is correct |
26 |
Correct |
217 ms |
27684 KB |
Output is correct |
27 |
Correct |
160 ms |
28824 KB |
Output is correct |
28 |
Correct |
149 ms |
28740 KB |
Output is correct |
29 |
Correct |
274 ms |
57960 KB |
Output is correct |
30 |
Correct |
280 ms |
57444 KB |
Output is correct |
31 |
Correct |
7 ms |
9684 KB |
Output is correct |
32 |
Correct |
604 ms |
60532 KB |
Output is correct |
33 |
Correct |
514 ms |
53400 KB |
Output is correct |
34 |
Correct |
153 ms |
27840 KB |
Output is correct |
35 |
Correct |
154 ms |
28040 KB |
Output is correct |
36 |
Correct |
581 ms |
60764 KB |
Output is correct |
37 |
Correct |
289 ms |
57948 KB |
Output is correct |
38 |
Correct |
296 ms |
57936 KB |
Output is correct |
39 |
Correct |
226 ms |
57484 KB |
Output is correct |
40 |
Correct |
264 ms |
42896 KB |
Output is correct |
41 |
Correct |
172 ms |
29108 KB |
Output is correct |
42 |
Correct |
6 ms |
9684 KB |
Output is correct |
43 |
Correct |
219 ms |
28232 KB |
Output is correct |
44 |
Correct |
253 ms |
28692 KB |
Output is correct |
45 |
Correct |
276 ms |
29644 KB |
Output is correct |
46 |
Correct |
244 ms |
30964 KB |
Output is correct |
47 |
Correct |
211 ms |
28696 KB |
Output is correct |
48 |
Correct |
179 ms |
29256 KB |
Output is correct |
49 |
Correct |
121 ms |
28656 KB |
Output is correct |
50 |
Correct |
114 ms |
19936 KB |
Output is correct |
51 |
Correct |
273 ms |
32468 KB |
Output is correct |
52 |
Correct |
170 ms |
27804 KB |
Output is correct |
53 |
Correct |
6 ms |
9684 KB |
Output is correct |
54 |
Correct |
6 ms |
9684 KB |
Output is correct |
55 |
Correct |
5 ms |
9616 KB |
Output is correct |
56 |
Correct |
7 ms |
10072 KB |
Output is correct |
57 |
Correct |
9 ms |
10068 KB |
Output is correct |
58 |
Correct |
8 ms |
9812 KB |
Output is correct |
59 |
Correct |
7 ms |
10068 KB |
Output is correct |
60 |
Correct |
7 ms |
9940 KB |
Output is correct |
61 |
Correct |
8 ms |
9832 KB |
Output is correct |
62 |
Correct |
8 ms |
10192 KB |
Output is correct |
63 |
Correct |
8 ms |
10196 KB |
Output is correct |
64 |
Correct |
8 ms |
10068 KB |
Output is correct |
65 |
Correct |
7 ms |
9812 KB |
Output is correct |
66 |
Correct |
6 ms |
9940 KB |
Output is correct |
67 |
Correct |
290 ms |
58064 KB |
Output is correct |
68 |
Correct |
156 ms |
27968 KB |
Output is correct |
69 |
Correct |
373 ms |
58412 KB |
Output is correct |
70 |
Correct |
397 ms |
52376 KB |
Output is correct |
71 |
Correct |
382 ms |
59904 KB |
Output is correct |
72 |
Correct |
207 ms |
27916 KB |
Output is correct |
73 |
Correct |
316 ms |
53772 KB |
Output is correct |
74 |
Correct |
270 ms |
50364 KB |
Output is correct |
75 |
Correct |
164 ms |
30088 KB |
Output is correct |
76 |
Correct |
214 ms |
27788 KB |
Output is correct |
77 |
Correct |
142 ms |
28916 KB |
Output is correct |
78 |
Correct |
175 ms |
28708 KB |
Output is correct |
79 |
Correct |
268 ms |
57948 KB |
Output is correct |
80 |
Correct |
215 ms |
57516 KB |
Output is correct |
81 |
Correct |
571 ms |
60408 KB |
Output is correct |
82 |
Correct |
541 ms |
53448 KB |
Output is correct |
83 |
Correct |
159 ms |
27896 KB |
Output is correct |
84 |
Correct |
176 ms |
28112 KB |
Output is correct |
85 |
Correct |
582 ms |
60740 KB |
Output is correct |
86 |
Correct |
258 ms |
57912 KB |
Output is correct |
87 |
Correct |
274 ms |
58016 KB |
Output is correct |
88 |
Correct |
243 ms |
42868 KB |
Output is correct |
89 |
Correct |
173 ms |
29116 KB |
Output is correct |
90 |
Correct |
276 ms |
28232 KB |
Output is correct |
91 |
Correct |
236 ms |
28548 KB |
Output is correct |
92 |
Correct |
288 ms |
29620 KB |
Output is correct |
93 |
Correct |
235 ms |
31028 KB |
Output is correct |
94 |
Correct |
239 ms |
28712 KB |
Output is correct |
95 |
Correct |
150 ms |
29168 KB |
Output is correct |
96 |
Correct |
99 ms |
28628 KB |
Output is correct |
97 |
Correct |
123 ms |
19980 KB |
Output is correct |
98 |
Correct |
223 ms |
32372 KB |
Output is correct |
99 |
Correct |
178 ms |
27860 KB |
Output is correct |
100 |
Correct |
52 ms |
12740 KB |
Output is correct |
101 |
Correct |
552 ms |
51916 KB |
Output is correct |
102 |
Correct |
182 ms |
25148 KB |
Output is correct |
103 |
Correct |
371 ms |
43724 KB |
Output is correct |
104 |
Correct |
612 ms |
57260 KB |
Output is correct |