#include <bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define all(vin) vin.begin(), vin.end()
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> tp;
const int N = 1e6 + 2;
//const int oo = 1e16;
int n, m, a[N], b[N];
vector<int> p[N], g[N], vr[N];
int w[N], pa[N], sz[N], t[N], mx[N];
int fin(int u){
return pa[u] == u ? u : pa[u] = fin(pa[u]);
}
void dsu(int x,int y,int j){
if(fin(x) == fin(y)) return;
x = fin(x);
y = fin(y);
int px = mx[x], py = mx[y];
g[px].push_back(py);
t[py] = min(t[py], j);
if(a[px] == a[py]) mx[y] = mx[x];
// cerr << px << " " << py << " " << j << " p\n";
if(sz[x] < sz[y]) swap(x, y);
sz[x] += sz[y];
pa[y] = x;
w[x] += w[y];
if(a[mx[y]] > a[mx[x]]) mx[x] = mx[y];
// else if(a[mx[y]] == a[mx[x]] && )
}
void dfs(int u,int v){
for(auto j : g[u]) if(j != v){
t[j] = min(t[j], t[u]);
dfs(j, u);
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")){
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n >> m;
vector<int> rrh;
for(int i = 1; i <= n; i ++){
cin >> a[i];
rrh.push_back(a[i]);
}
sort(all(rrh));
rrh.resize(unique(all(rrh)) - rrh.begin());
for(int i = 1; i <= n; i ++){
b[i] = lower_bound(all(rrh), a[i]) - rrh.begin() + 1;
vr[b[i]].push_back(i);
}
for(int i = 1; i <= m; i ++){
int x, y; cin >> x >> y;
p[x].push_back(y);
p[y].push_back(x);
}
// for(int i = 1; i <= n; i ++) cerr << i << " " << a[i] << " y\n";
for(int i = 1; i <= n; i ++) pa[i] = i, sz[i] = 1, w[i] = a[i], t[i] = 1, mx[i] = i;
for(int k = 1; k <= (int)rrh.size(); k ++){
int val = rrh[k - 1];
for(auto i : vr[k]){
for(auto j : p[i]) if(a[j] == a[i]){
dsu(i, j, 1);
}else if(a[j] < a[i]){
if(w[fin(j)] >= a[i]) dsu(i, j, 1);
else dsu(i, j, 0);
}
}
}
int root = mx[fin(1)];
dfs(root, 0);
for(int i = 1; i <= n; i ++) cout << t[i];
}
/*
12 16
92 43 33 70 2 19 58 78 79 34 22 19
1 2
1 3
3 4
1 5
5 6
1 7
3 8
3 9
3 10
1 11
2 12
12 2
4 10
3 9
4 3
5 12
*/
Compilation message
island.cpp: In function 'int main()':
island.cpp:81:9: warning: unused variable 'val' [-Wunused-variable]
81 | int val = rrh[k - 1];
| ^~~
island.cpp:55:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | freopen(task ".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
island.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen(task ".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
70748 KB |
Output is correct |
2 |
Correct |
34 ms |
70748 KB |
Output is correct |
3 |
Correct |
34 ms |
70740 KB |
Output is correct |
4 |
Correct |
36 ms |
71120 KB |
Output is correct |
5 |
Correct |
35 ms |
71252 KB |
Output is correct |
6 |
Correct |
35 ms |
70992 KB |
Output is correct |
7 |
Correct |
34 ms |
71252 KB |
Output is correct |
8 |
Correct |
33 ms |
70996 KB |
Output is correct |
9 |
Correct |
34 ms |
71248 KB |
Output is correct |
10 |
Correct |
35 ms |
71260 KB |
Output is correct |
11 |
Correct |
38 ms |
71248 KB |
Output is correct |
12 |
Correct |
33 ms |
71260 KB |
Output is correct |
13 |
Correct |
34 ms |
70996 KB |
Output is correct |
14 |
Correct |
34 ms |
71164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
70740 KB |
Output is correct |
2 |
Correct |
35 ms |
70736 KB |
Output is correct |
3 |
Correct |
161 ms |
109616 KB |
Output is correct |
4 |
Correct |
126 ms |
98420 KB |
Output is correct |
5 |
Correct |
180 ms |
104640 KB |
Output is correct |
6 |
Correct |
180 ms |
104820 KB |
Output is correct |
7 |
Correct |
175 ms |
105668 KB |
Output is correct |
8 |
Correct |
138 ms |
99656 KB |
Output is correct |
9 |
Correct |
151 ms |
104132 KB |
Output is correct |
10 |
Correct |
140 ms |
102956 KB |
Output is correct |
11 |
Correct |
122 ms |
99260 KB |
Output is correct |
12 |
Correct |
144 ms |
98164 KB |
Output is correct |
13 |
Correct |
121 ms |
97228 KB |
Output is correct |
14 |
Correct |
123 ms |
97472 KB |
Output is correct |
15 |
Correct |
157 ms |
116220 KB |
Output is correct |
16 |
Correct |
125 ms |
115140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
70820 KB |
Output is correct |
2 |
Correct |
253 ms |
104484 KB |
Output is correct |
3 |
Correct |
219 ms |
103624 KB |
Output is correct |
4 |
Correct |
127 ms |
98636 KB |
Output is correct |
5 |
Correct |
120 ms |
97096 KB |
Output is correct |
6 |
Correct |
226 ms |
104644 KB |
Output is correct |
7 |
Correct |
177 ms |
116100 KB |
Output is correct |
8 |
Correct |
178 ms |
116168 KB |
Output is correct |
9 |
Correct |
116 ms |
115144 KB |
Output is correct |
10 |
Correct |
141 ms |
105336 KB |
Output is correct |
11 |
Correct |
133 ms |
100040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
70740 KB |
Output is correct |
2 |
Correct |
176 ms |
101576 KB |
Output is correct |
3 |
Correct |
175 ms |
101316 KB |
Output is correct |
4 |
Correct |
163 ms |
101260 KB |
Output is correct |
5 |
Correct |
162 ms |
99908 KB |
Output is correct |
6 |
Correct |
153 ms |
99396 KB |
Output is correct |
7 |
Correct |
131 ms |
106252 KB |
Output is correct |
8 |
Correct |
108 ms |
104904 KB |
Output is correct |
9 |
Correct |
113 ms |
88944 KB |
Output is correct |
10 |
Correct |
156 ms |
98372 KB |
Output is correct |
11 |
Correct |
125 ms |
100040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
70748 KB |
Output is correct |
2 |
Correct |
34 ms |
70748 KB |
Output is correct |
3 |
Correct |
34 ms |
70740 KB |
Output is correct |
4 |
Correct |
36 ms |
71120 KB |
Output is correct |
5 |
Correct |
35 ms |
71252 KB |
Output is correct |
6 |
Correct |
35 ms |
70992 KB |
Output is correct |
7 |
Correct |
34 ms |
71252 KB |
Output is correct |
8 |
Correct |
33 ms |
70996 KB |
Output is correct |
9 |
Correct |
34 ms |
71248 KB |
Output is correct |
10 |
Correct |
35 ms |
71260 KB |
Output is correct |
11 |
Correct |
38 ms |
71248 KB |
Output is correct |
12 |
Correct |
33 ms |
71260 KB |
Output is correct |
13 |
Correct |
34 ms |
70996 KB |
Output is correct |
14 |
Correct |
34 ms |
71164 KB |
Output is correct |
15 |
Correct |
34 ms |
70740 KB |
Output is correct |
16 |
Correct |
35 ms |
70736 KB |
Output is correct |
17 |
Correct |
161 ms |
109616 KB |
Output is correct |
18 |
Correct |
126 ms |
98420 KB |
Output is correct |
19 |
Correct |
180 ms |
104640 KB |
Output is correct |
20 |
Correct |
180 ms |
104820 KB |
Output is correct |
21 |
Correct |
175 ms |
105668 KB |
Output is correct |
22 |
Correct |
138 ms |
99656 KB |
Output is correct |
23 |
Correct |
151 ms |
104132 KB |
Output is correct |
24 |
Correct |
140 ms |
102956 KB |
Output is correct |
25 |
Correct |
122 ms |
99260 KB |
Output is correct |
26 |
Correct |
144 ms |
98164 KB |
Output is correct |
27 |
Correct |
121 ms |
97228 KB |
Output is correct |
28 |
Correct |
123 ms |
97472 KB |
Output is correct |
29 |
Correct |
157 ms |
116220 KB |
Output is correct |
30 |
Correct |
125 ms |
115140 KB |
Output is correct |
31 |
Correct |
35 ms |
70820 KB |
Output is correct |
32 |
Correct |
253 ms |
104484 KB |
Output is correct |
33 |
Correct |
219 ms |
103624 KB |
Output is correct |
34 |
Correct |
127 ms |
98636 KB |
Output is correct |
35 |
Correct |
120 ms |
97096 KB |
Output is correct |
36 |
Correct |
226 ms |
104644 KB |
Output is correct |
37 |
Correct |
177 ms |
116100 KB |
Output is correct |
38 |
Correct |
178 ms |
116168 KB |
Output is correct |
39 |
Correct |
116 ms |
115144 KB |
Output is correct |
40 |
Correct |
141 ms |
105336 KB |
Output is correct |
41 |
Correct |
133 ms |
100040 KB |
Output is correct |
42 |
Correct |
30 ms |
70740 KB |
Output is correct |
43 |
Correct |
176 ms |
101576 KB |
Output is correct |
44 |
Correct |
175 ms |
101316 KB |
Output is correct |
45 |
Correct |
163 ms |
101260 KB |
Output is correct |
46 |
Correct |
162 ms |
99908 KB |
Output is correct |
47 |
Correct |
153 ms |
99396 KB |
Output is correct |
48 |
Correct |
131 ms |
106252 KB |
Output is correct |
49 |
Correct |
108 ms |
104904 KB |
Output is correct |
50 |
Correct |
113 ms |
88944 KB |
Output is correct |
51 |
Correct |
156 ms |
98372 KB |
Output is correct |
52 |
Correct |
125 ms |
100040 KB |
Output is correct |
53 |
Correct |
33 ms |
70744 KB |
Output is correct |
54 |
Correct |
33 ms |
70736 KB |
Output is correct |
55 |
Correct |
34 ms |
70748 KB |
Output is correct |
56 |
Correct |
31 ms |
71260 KB |
Output is correct |
57 |
Correct |
34 ms |
71252 KB |
Output is correct |
58 |
Correct |
33 ms |
71000 KB |
Output is correct |
59 |
Correct |
33 ms |
71260 KB |
Output is correct |
60 |
Correct |
33 ms |
71000 KB |
Output is correct |
61 |
Correct |
29 ms |
71260 KB |
Output is correct |
62 |
Correct |
30 ms |
71252 KB |
Output is correct |
63 |
Correct |
32 ms |
71188 KB |
Output is correct |
64 |
Correct |
30 ms |
71260 KB |
Output is correct |
65 |
Correct |
35 ms |
71164 KB |
Output is correct |
66 |
Correct |
36 ms |
71248 KB |
Output is correct |
67 |
Correct |
144 ms |
109512 KB |
Output is correct |
68 |
Correct |
132 ms |
98320 KB |
Output is correct |
69 |
Correct |
166 ms |
104480 KB |
Output is correct |
70 |
Correct |
181 ms |
104384 KB |
Output is correct |
71 |
Correct |
157 ms |
105720 KB |
Output is correct |
72 |
Correct |
125 ms |
99652 KB |
Output is correct |
73 |
Correct |
136 ms |
104140 KB |
Output is correct |
74 |
Correct |
180 ms |
103112 KB |
Output is correct |
75 |
Correct |
123 ms |
99140 KB |
Output is correct |
76 |
Correct |
144 ms |
98248 KB |
Output is correct |
77 |
Correct |
110 ms |
97096 KB |
Output is correct |
78 |
Correct |
113 ms |
97480 KB |
Output is correct |
79 |
Correct |
153 ms |
116172 KB |
Output is correct |
80 |
Correct |
128 ms |
115060 KB |
Output is correct |
81 |
Correct |
219 ms |
104388 KB |
Output is correct |
82 |
Correct |
259 ms |
103624 KB |
Output is correct |
83 |
Correct |
120 ms |
98632 KB |
Output is correct |
84 |
Correct |
133 ms |
97104 KB |
Output is correct |
85 |
Correct |
232 ms |
104648 KB |
Output is correct |
86 |
Correct |
170 ms |
116108 KB |
Output is correct |
87 |
Correct |
163 ms |
116144 KB |
Output is correct |
88 |
Correct |
144 ms |
105280 KB |
Output is correct |
89 |
Correct |
126 ms |
100040 KB |
Output is correct |
90 |
Correct |
156 ms |
101576 KB |
Output is correct |
91 |
Correct |
152 ms |
101232 KB |
Output is correct |
92 |
Correct |
149 ms |
101312 KB |
Output is correct |
93 |
Correct |
140 ms |
99908 KB |
Output is correct |
94 |
Correct |
157 ms |
99396 KB |
Output is correct |
95 |
Correct |
108 ms |
106208 KB |
Output is correct |
96 |
Correct |
84 ms |
104904 KB |
Output is correct |
97 |
Correct |
95 ms |
89548 KB |
Output is correct |
98 |
Correct |
130 ms |
98572 KB |
Output is correct |
99 |
Correct |
107 ms |
101968 KB |
Output is correct |
100 |
Correct |
45 ms |
79236 KB |
Output is correct |
101 |
Correct |
204 ms |
104644 KB |
Output is correct |
102 |
Correct |
124 ms |
95808 KB |
Output is correct |
103 |
Correct |
174 ms |
102632 KB |
Output is correct |
104 |
Correct |
236 ms |
106184 KB |
Output is correct |