#include <bits/stdc++.h>
#define se second
#define fs first
#define mp make_pair
#define pb push_back
#define ll long long
#define ii pair<ll,ll>
#define ld long double
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }
const int N = 2e5 + 7;
const int Mod = 998244353;
const int szBL = 916;
const int INF = 1e9;
const int BASE = 137;
int n, m;
vector<int> ke[N];
int a[N];
pair<int,int> b[N];
bool Ans[N];
int larger[N];
struct Disjoin_set {
int lab[N], sz[N], tot[N];
vector<int> vec[N];
set<pair<int,int>> Sadj[N];///greater val
void init (int n) {
rep (i, 1, n) {
lab[i] = i, sz[i] = 1, tot[i] = a[i];
vec[i] = {i};
iter (&id, ke[i]) {
Sadj[i].insert(mp(a[id], id));
}
}
}
int Find (int u) {
return u == lab[u] ? u : Find(lab[u]);
}
void Join (int u, int v) {
u = Find(u);
v = Find(v);
if (u == v) return;
if (sz[u] < sz[v]) swap(u, v);
lab[v] = u;
sz[u] += sz[v];
iter (&id, vec[v]) {
iter (&idto, ke[id]) {
Sadj[u].insert(mp(a[idto], idto));
}
vec[u].push_back(id);
}
tot[u] += tot[v];
tot[u] = min(tot[u], INF);
vector<int> ().swap(vec[v]);
}
int Find_Larger (int u) {
int idx = u;
u = Find(u);
auto it = Sadj[u].lower_bound(mp(a[idx] + 1, -INF));
if (it == Sadj[u].end()) return 0;
else return it->se;
}
}DSU;
void solution () {
cin >> n >> m;
rep (i, 1, n) {
cin >> a[i];
b[i].fs = a[i];
b[i].se = i;
}
rep (i, 1, m) {
int u, v;
cin >> u >> v;
ke[u].push_back(v);
ke[v].push_back(u);
}
DSU.init(n);
sort (b + 1, b + 1 + n);
rep (i, 1, n) {
static vector<int> vec; vec.clear();
while (b[i].fs == b[i + 1].fs) vec.push_back(b[i++].se);
vec.push_back(b[i].se);
iter (&idx, vec) {
iter (&to, ke[idx]) {
if (a[idx] >= a[to]) DSU.Join (idx, to);
}
}
iter (&idx, vec) {
larger[idx] = DSU.Find_Larger(idx);
if (DSU.tot[DSU.Find(idx)] < a[larger[idx]]) {
larger[idx] = -1;
}
}
}
Ans[0] = 1;
reb (i, n, 1) {
if (Ans[b[i].se] == -1) Ans[b[i].se] = 0;
else Ans[b[i].se] = Ans[larger[b[i].se]];
}
rep (i ,1, n) cout << Ans[i];
}
#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
int main () {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// file ("c");
int num_Test = 1;
// cin >> num_Test;
while (num_Test--)
solution();
}
/*
5 10
1 2
3 1
4 2
5 3
1 4
2 3
3 5
4 5
3 4
1 4
*/
Compilation message
island.cpp: In function 'void solution()':
island.cpp:115:26: warning: comparison of constant '-1' with boolean expression is always false [-Wbool-compare]
115 | if (Ans[b[i].se] == -1) Ans[b[i].se] = 0;
| ~~~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24668 KB |
Output is correct |
2 |
Correct |
3 ms |
24668 KB |
Output is correct |
3 |
Correct |
4 ms |
24664 KB |
Output is correct |
4 |
Correct |
6 ms |
25180 KB |
Output is correct |
5 |
Correct |
7 ms |
25180 KB |
Output is correct |
6 |
Correct |
6 ms |
25244 KB |
Output is correct |
7 |
Correct |
6 ms |
25000 KB |
Output is correct |
8 |
Correct |
5 ms |
25180 KB |
Output is correct |
9 |
Correct |
4 ms |
25180 KB |
Output is correct |
10 |
Correct |
7 ms |
25436 KB |
Output is correct |
11 |
Correct |
6 ms |
25436 KB |
Output is correct |
12 |
Correct |
9 ms |
25328 KB |
Output is correct |
13 |
Correct |
5 ms |
25176 KB |
Output is correct |
14 |
Correct |
6 ms |
25180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24668 KB |
Output is correct |
2 |
Correct |
4 ms |
24692 KB |
Output is correct |
3 |
Correct |
171 ms |
71892 KB |
Output is correct |
4 |
Correct |
169 ms |
68268 KB |
Output is correct |
5 |
Correct |
464 ms |
96276 KB |
Output is correct |
6 |
Correct |
520 ms |
101120 KB |
Output is correct |
7 |
Correct |
508 ms |
99796 KB |
Output is correct |
8 |
Correct |
291 ms |
67276 KB |
Output is correct |
9 |
Correct |
464 ms |
131896 KB |
Output is correct |
10 |
Correct |
208 ms |
58368 KB |
Output is correct |
11 |
Correct |
222 ms |
59204 KB |
Output is correct |
12 |
Correct |
342 ms |
74704 KB |
Output is correct |
13 |
Correct |
169 ms |
67260 KB |
Output is correct |
14 |
Correct |
177 ms |
68292 KB |
Output is correct |
15 |
Correct |
160 ms |
66492 KB |
Output is correct |
16 |
Correct |
156 ms |
65988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24664 KB |
Output is correct |
2 |
Correct |
642 ms |
116152 KB |
Output is correct |
3 |
Correct |
614 ms |
115968 KB |
Output is correct |
4 |
Correct |
206 ms |
67268 KB |
Output is correct |
5 |
Correct |
184 ms |
70596 KB |
Output is correct |
6 |
Correct |
612 ms |
114968 KB |
Output is correct |
7 |
Correct |
192 ms |
66472 KB |
Output is correct |
8 |
Correct |
204 ms |
66504 KB |
Output is correct |
9 |
Correct |
150 ms |
65984 KB |
Output is correct |
10 |
Correct |
159 ms |
71624 KB |
Output is correct |
11 |
Correct |
273 ms |
81096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24668 KB |
Output is correct |
2 |
Correct |
490 ms |
88780 KB |
Output is correct |
3 |
Correct |
525 ms |
93608 KB |
Output is correct |
4 |
Correct |
598 ms |
100816 KB |
Output is correct |
5 |
Correct |
500 ms |
96380 KB |
Output is correct |
6 |
Correct |
398 ms |
84940 KB |
Output is correct |
7 |
Correct |
270 ms |
69164 KB |
Output is correct |
8 |
Correct |
154 ms |
66848 KB |
Output is correct |
9 |
Correct |
315 ms |
67648 KB |
Output is correct |
10 |
Correct |
547 ms |
103556 KB |
Output is correct |
11 |
Correct |
313 ms |
79048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
24668 KB |
Output is correct |
2 |
Correct |
3 ms |
24668 KB |
Output is correct |
3 |
Correct |
4 ms |
24664 KB |
Output is correct |
4 |
Correct |
6 ms |
25180 KB |
Output is correct |
5 |
Correct |
7 ms |
25180 KB |
Output is correct |
6 |
Correct |
6 ms |
25244 KB |
Output is correct |
7 |
Correct |
6 ms |
25000 KB |
Output is correct |
8 |
Correct |
5 ms |
25180 KB |
Output is correct |
9 |
Correct |
4 ms |
25180 KB |
Output is correct |
10 |
Correct |
7 ms |
25436 KB |
Output is correct |
11 |
Correct |
6 ms |
25436 KB |
Output is correct |
12 |
Correct |
9 ms |
25328 KB |
Output is correct |
13 |
Correct |
5 ms |
25176 KB |
Output is correct |
14 |
Correct |
6 ms |
25180 KB |
Output is correct |
15 |
Correct |
4 ms |
24668 KB |
Output is correct |
16 |
Correct |
4 ms |
24692 KB |
Output is correct |
17 |
Correct |
171 ms |
71892 KB |
Output is correct |
18 |
Correct |
169 ms |
68268 KB |
Output is correct |
19 |
Correct |
464 ms |
96276 KB |
Output is correct |
20 |
Correct |
520 ms |
101120 KB |
Output is correct |
21 |
Correct |
508 ms |
99796 KB |
Output is correct |
22 |
Correct |
291 ms |
67276 KB |
Output is correct |
23 |
Correct |
464 ms |
131896 KB |
Output is correct |
24 |
Correct |
208 ms |
58368 KB |
Output is correct |
25 |
Correct |
222 ms |
59204 KB |
Output is correct |
26 |
Correct |
342 ms |
74704 KB |
Output is correct |
27 |
Correct |
169 ms |
67260 KB |
Output is correct |
28 |
Correct |
177 ms |
68292 KB |
Output is correct |
29 |
Correct |
160 ms |
66492 KB |
Output is correct |
30 |
Correct |
156 ms |
65988 KB |
Output is correct |
31 |
Correct |
4 ms |
24664 KB |
Output is correct |
32 |
Correct |
642 ms |
116152 KB |
Output is correct |
33 |
Correct |
614 ms |
115968 KB |
Output is correct |
34 |
Correct |
206 ms |
67268 KB |
Output is correct |
35 |
Correct |
184 ms |
70596 KB |
Output is correct |
36 |
Correct |
612 ms |
114968 KB |
Output is correct |
37 |
Correct |
192 ms |
66472 KB |
Output is correct |
38 |
Correct |
204 ms |
66504 KB |
Output is correct |
39 |
Correct |
150 ms |
65984 KB |
Output is correct |
40 |
Correct |
159 ms |
71624 KB |
Output is correct |
41 |
Correct |
273 ms |
81096 KB |
Output is correct |
42 |
Correct |
4 ms |
24668 KB |
Output is correct |
43 |
Correct |
490 ms |
88780 KB |
Output is correct |
44 |
Correct |
525 ms |
93608 KB |
Output is correct |
45 |
Correct |
598 ms |
100816 KB |
Output is correct |
46 |
Correct |
500 ms |
96380 KB |
Output is correct |
47 |
Correct |
398 ms |
84940 KB |
Output is correct |
48 |
Correct |
270 ms |
69164 KB |
Output is correct |
49 |
Correct |
154 ms |
66848 KB |
Output is correct |
50 |
Correct |
315 ms |
67648 KB |
Output is correct |
51 |
Correct |
547 ms |
103556 KB |
Output is correct |
52 |
Correct |
313 ms |
79048 KB |
Output is correct |
53 |
Correct |
4 ms |
24664 KB |
Output is correct |
54 |
Correct |
4 ms |
24664 KB |
Output is correct |
55 |
Correct |
4 ms |
24668 KB |
Output is correct |
56 |
Correct |
7 ms |
25180 KB |
Output is correct |
57 |
Correct |
6 ms |
25180 KB |
Output is correct |
58 |
Correct |
6 ms |
25180 KB |
Output is correct |
59 |
Correct |
5 ms |
25180 KB |
Output is correct |
60 |
Correct |
6 ms |
25180 KB |
Output is correct |
61 |
Correct |
5 ms |
25180 KB |
Output is correct |
62 |
Correct |
7 ms |
25432 KB |
Output is correct |
63 |
Correct |
6 ms |
25436 KB |
Output is correct |
64 |
Correct |
6 ms |
25476 KB |
Output is correct |
65 |
Correct |
5 ms |
25180 KB |
Output is correct |
66 |
Correct |
6 ms |
25256 KB |
Output is correct |
67 |
Correct |
184 ms |
71720 KB |
Output is correct |
68 |
Correct |
161 ms |
68300 KB |
Output is correct |
69 |
Correct |
446 ms |
96360 KB |
Output is correct |
70 |
Correct |
579 ms |
101000 KB |
Output is correct |
71 |
Correct |
527 ms |
99928 KB |
Output is correct |
72 |
Correct |
296 ms |
67276 KB |
Output is correct |
73 |
Correct |
450 ms |
131884 KB |
Output is correct |
74 |
Correct |
217 ms |
58312 KB |
Output is correct |
75 |
Correct |
223 ms |
59128 KB |
Output is correct |
76 |
Correct |
337 ms |
74696 KB |
Output is correct |
77 |
Correct |
175 ms |
67268 KB |
Output is correct |
78 |
Correct |
170 ms |
68296 KB |
Output is correct |
79 |
Correct |
160 ms |
66400 KB |
Output is correct |
80 |
Correct |
151 ms |
66192 KB |
Output is correct |
81 |
Correct |
621 ms |
116212 KB |
Output is correct |
82 |
Correct |
613 ms |
116040 KB |
Output is correct |
83 |
Correct |
193 ms |
67268 KB |
Output is correct |
84 |
Correct |
185 ms |
70592 KB |
Output is correct |
85 |
Correct |
627 ms |
114968 KB |
Output is correct |
86 |
Correct |
192 ms |
66408 KB |
Output is correct |
87 |
Correct |
193 ms |
66500 KB |
Output is correct |
88 |
Correct |
167 ms |
71620 KB |
Output is correct |
89 |
Correct |
263 ms |
81092 KB |
Output is correct |
90 |
Correct |
495 ms |
88700 KB |
Output is correct |
91 |
Correct |
507 ms |
93656 KB |
Output is correct |
92 |
Correct |
584 ms |
100988 KB |
Output is correct |
93 |
Correct |
497 ms |
96316 KB |
Output is correct |
94 |
Correct |
416 ms |
84940 KB |
Output is correct |
95 |
Correct |
264 ms |
69012 KB |
Output is correct |
96 |
Correct |
156 ms |
66796 KB |
Output is correct |
97 |
Correct |
308 ms |
67784 KB |
Output is correct |
98 |
Correct |
559 ms |
103624 KB |
Output is correct |
99 |
Correct |
265 ms |
79048 KB |
Output is correct |
100 |
Correct |
115 ms |
45904 KB |
Output is correct |
101 |
Correct |
523 ms |
97648 KB |
Output is correct |
102 |
Correct |
346 ms |
77512 KB |
Output is correct |
103 |
Correct |
363 ms |
74696 KB |
Output is correct |
104 |
Correct |
447 ms |
84676 KB |
Output is correct |