//author : FatihCihan
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
const int N = 2e5 + 7;
const int inf = 1e18 + 7;
int n,m,s[N],ans[N],mem_value[N],mem_par[N],tar[N];
vector < int > graph[N] , adj[N];
int par[N] , value[N] , mx[N];
int find(int a){
if(par[a] == a)return a;
else return par[a] = find(par[a]);
}
void merge(int a , int b){
a = find(a) , b = find(b);
if(a == b)return;
value[b] += value[a];
par[a] = b;
if(s[mx[a]] > s[mx[b]])mx[b] = mx[a];
}
void solve(){
cin >> n >> m;
pair < int , int > village[n];
vector < int > compr;
for(int i = 1;i<=n;i++){
cin >> s[i];
village[i-1] = {s[i] , i};
tar[i] = inf;
par[i] = mx[i] = i , value[i] = s[i];
compr.push_back(s[i]);
}
sort(all(compr));
compr.resize(unique(all(compr)) - compr.begin());
sort(village , village + n);
for(int i = 0;i<m;i++){
int ai,bi;
cin >> ai >> bi;
graph[ai].push_back(bi);
graph[bi].push_back(ai);
}
int lp = 0;
for(auto si : compr){
// cout << " SI : " << si << endl;
vector < int > v;
while(lp < n and s[village[lp].second] <= si){
v.push_back(village[lp].second);
// cout << "v : " << village[lp].second << endl;
lp++;
}
vector < pair < int , int > > gh;
for(auto node : v){
for(auto itr : graph[node]){
if(s[itr] < s[node]){
gh.push_back({node , mx[find(itr)]});
}
}
}
for(auto node : v){
for(auto itr : graph[node]){
if(s[itr] <= s[node]){
merge(itr , node);
}
}
}
// cout << "gh : ";
for(auto itr : gh){
// cout << itr.first << "," << itr.second << " ";
adj[find(itr.first)].push_back(itr.second);
}
// cout << endl;
for(auto node : v){
mem_value[node] = value[find(node)];
mem_par[node] = find(node);
// cout << node << " : " << mem_value[node] << " , " << mem_par[node] << endl;
}
// cout << "dsu : ";for(int i = 1;i<=n;i++)cout << i << ":" << find(i) << " ";cout << endl;
}
// cout << " ENDED" << endl;
for(int i = 1;i<=n;i++){
sort(all(adj[i]));
adj[i].resize(unique(all(adj[i])) - adj[i].begin());
}
int mx_s = village[n-1].first;
for(int i = 1;i<=n;i++){
if(s[i] == mx_s){
tar[i] = 0;
}
}
for(int i = n-1;i>=0;i--){
// cout << "equal : " << village[i].second << " " << mem_par[village[i].second] << endl;
// cout << "values : " << tar[village[i].second] << " " << mem_value[village[i].second] << endl;
if(mem_par[village[i].second] != village[i].second)37;
else if(tar[village[i].second] <= mem_value[village[i].second]){
ans[village[i].second] = 1;
// cout << "adj " << village[i].second << " : ";
for(auto itr : adj[village[i].second]){
// cout << itr << " ";
tar[itr] = min(tar[itr] , s[village[i].second]);
}
// cout << endl;
}
else{
ans[village[i].second] = 0;
}
// cout << endl;
}
for(int i = 1;i<=n;i++){
cout << ans[mem_par[i]];
}
cout << endl;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
// cerr << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl;
}
Compilation message
island.cpp: In function 'void solve()':
island.cpp:96:54: warning: statement has no effect [-Wunused-value]
96 | if(mem_par[village[i].second] != village[i].second)37;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
20828 KB |
Output is correct |
2 |
Correct |
3 ms |
20828 KB |
Output is correct |
3 |
Correct |
4 ms |
20828 KB |
Output is correct |
4 |
Correct |
5 ms |
21084 KB |
Output is correct |
5 |
Correct |
5 ms |
21084 KB |
Output is correct |
6 |
Correct |
4 ms |
21084 KB |
Output is correct |
7 |
Correct |
5 ms |
21080 KB |
Output is correct |
8 |
Correct |
5 ms |
21084 KB |
Output is correct |
9 |
Correct |
4 ms |
21084 KB |
Output is correct |
10 |
Correct |
5 ms |
21084 KB |
Output is correct |
11 |
Correct |
5 ms |
21084 KB |
Output is correct |
12 |
Correct |
4 ms |
21084 KB |
Output is correct |
13 |
Correct |
4 ms |
21084 KB |
Output is correct |
14 |
Correct |
5 ms |
21084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
20828 KB |
Output is correct |
2 |
Correct |
4 ms |
20828 KB |
Output is correct |
3 |
Correct |
126 ms |
38688 KB |
Output is correct |
4 |
Correct |
93 ms |
38824 KB |
Output is correct |
5 |
Correct |
128 ms |
42252 KB |
Output is correct |
6 |
Correct |
146 ms |
42868 KB |
Output is correct |
7 |
Correct |
137 ms |
42856 KB |
Output is correct |
8 |
Correct |
108 ms |
40292 KB |
Output is correct |
9 |
Correct |
122 ms |
42432 KB |
Output is correct |
10 |
Correct |
106 ms |
45124 KB |
Output is correct |
11 |
Correct |
96 ms |
41168 KB |
Output is correct |
12 |
Correct |
108 ms |
38728 KB |
Output is correct |
13 |
Correct |
86 ms |
37704 KB |
Output is correct |
14 |
Correct |
91 ms |
37820 KB |
Output is correct |
15 |
Correct |
125 ms |
44224 KB |
Output is correct |
16 |
Correct |
90 ms |
43208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
20828 KB |
Output is correct |
2 |
Correct |
193 ms |
37412 KB |
Output is correct |
3 |
Correct |
193 ms |
41956 KB |
Output is correct |
4 |
Correct |
105 ms |
40880 KB |
Output is correct |
5 |
Correct |
88 ms |
37948 KB |
Output is correct |
6 |
Correct |
229 ms |
42052 KB |
Output is correct |
7 |
Correct |
149 ms |
44184 KB |
Output is correct |
8 |
Correct |
157 ms |
44188 KB |
Output is correct |
9 |
Correct |
90 ms |
43308 KB |
Output is correct |
10 |
Correct |
133 ms |
45888 KB |
Output is correct |
11 |
Correct |
121 ms |
41160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
20828 KB |
Output is correct |
2 |
Correct |
233 ms |
38676 KB |
Output is correct |
3 |
Correct |
195 ms |
42996 KB |
Output is correct |
4 |
Correct |
233 ms |
43312 KB |
Output is correct |
5 |
Correct |
182 ms |
41668 KB |
Output is correct |
6 |
Correct |
145 ms |
39684 KB |
Output is correct |
7 |
Correct |
101 ms |
43388 KB |
Output is correct |
8 |
Correct |
97 ms |
43692 KB |
Output is correct |
9 |
Correct |
89 ms |
35132 KB |
Output is correct |
10 |
Correct |
140 ms |
38972 KB |
Output is correct |
11 |
Correct |
134 ms |
40884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
20828 KB |
Output is correct |
2 |
Correct |
3 ms |
20828 KB |
Output is correct |
3 |
Correct |
4 ms |
20828 KB |
Output is correct |
4 |
Correct |
5 ms |
21084 KB |
Output is correct |
5 |
Correct |
5 ms |
21084 KB |
Output is correct |
6 |
Correct |
4 ms |
21084 KB |
Output is correct |
7 |
Correct |
5 ms |
21080 KB |
Output is correct |
8 |
Correct |
5 ms |
21084 KB |
Output is correct |
9 |
Correct |
4 ms |
21084 KB |
Output is correct |
10 |
Correct |
5 ms |
21084 KB |
Output is correct |
11 |
Correct |
5 ms |
21084 KB |
Output is correct |
12 |
Correct |
4 ms |
21084 KB |
Output is correct |
13 |
Correct |
4 ms |
21084 KB |
Output is correct |
14 |
Correct |
5 ms |
21084 KB |
Output is correct |
15 |
Correct |
4 ms |
20828 KB |
Output is correct |
16 |
Correct |
4 ms |
20828 KB |
Output is correct |
17 |
Correct |
126 ms |
38688 KB |
Output is correct |
18 |
Correct |
93 ms |
38824 KB |
Output is correct |
19 |
Correct |
128 ms |
42252 KB |
Output is correct |
20 |
Correct |
146 ms |
42868 KB |
Output is correct |
21 |
Correct |
137 ms |
42856 KB |
Output is correct |
22 |
Correct |
108 ms |
40292 KB |
Output is correct |
23 |
Correct |
122 ms |
42432 KB |
Output is correct |
24 |
Correct |
106 ms |
45124 KB |
Output is correct |
25 |
Correct |
96 ms |
41168 KB |
Output is correct |
26 |
Correct |
108 ms |
38728 KB |
Output is correct |
27 |
Correct |
86 ms |
37704 KB |
Output is correct |
28 |
Correct |
91 ms |
37820 KB |
Output is correct |
29 |
Correct |
125 ms |
44224 KB |
Output is correct |
30 |
Correct |
90 ms |
43208 KB |
Output is correct |
31 |
Correct |
3 ms |
20828 KB |
Output is correct |
32 |
Correct |
193 ms |
37412 KB |
Output is correct |
33 |
Correct |
193 ms |
41956 KB |
Output is correct |
34 |
Correct |
105 ms |
40880 KB |
Output is correct |
35 |
Correct |
88 ms |
37948 KB |
Output is correct |
36 |
Correct |
229 ms |
42052 KB |
Output is correct |
37 |
Correct |
149 ms |
44184 KB |
Output is correct |
38 |
Correct |
157 ms |
44188 KB |
Output is correct |
39 |
Correct |
90 ms |
43308 KB |
Output is correct |
40 |
Correct |
133 ms |
45888 KB |
Output is correct |
41 |
Correct |
121 ms |
41160 KB |
Output is correct |
42 |
Correct |
6 ms |
20828 KB |
Output is correct |
43 |
Correct |
233 ms |
38676 KB |
Output is correct |
44 |
Correct |
195 ms |
42996 KB |
Output is correct |
45 |
Correct |
233 ms |
43312 KB |
Output is correct |
46 |
Correct |
182 ms |
41668 KB |
Output is correct |
47 |
Correct |
145 ms |
39684 KB |
Output is correct |
48 |
Correct |
101 ms |
43388 KB |
Output is correct |
49 |
Correct |
97 ms |
43692 KB |
Output is correct |
50 |
Correct |
89 ms |
35132 KB |
Output is correct |
51 |
Correct |
140 ms |
38972 KB |
Output is correct |
52 |
Correct |
134 ms |
40884 KB |
Output is correct |
53 |
Correct |
4 ms |
20824 KB |
Output is correct |
54 |
Correct |
4 ms |
20828 KB |
Output is correct |
55 |
Correct |
5 ms |
20916 KB |
Output is correct |
56 |
Correct |
5 ms |
21080 KB |
Output is correct |
57 |
Correct |
5 ms |
21084 KB |
Output is correct |
58 |
Correct |
7 ms |
21084 KB |
Output is correct |
59 |
Correct |
5 ms |
21084 KB |
Output is correct |
60 |
Correct |
5 ms |
21084 KB |
Output is correct |
61 |
Correct |
4 ms |
21084 KB |
Output is correct |
62 |
Correct |
5 ms |
21192 KB |
Output is correct |
63 |
Correct |
5 ms |
21084 KB |
Output is correct |
64 |
Correct |
5 ms |
21084 KB |
Output is correct |
65 |
Correct |
5 ms |
21080 KB |
Output is correct |
66 |
Correct |
7 ms |
21084 KB |
Output is correct |
67 |
Correct |
139 ms |
43104 KB |
Output is correct |
68 |
Correct |
113 ms |
38920 KB |
Output is correct |
69 |
Correct |
168 ms |
42216 KB |
Output is correct |
70 |
Correct |
178 ms |
42952 KB |
Output is correct |
71 |
Correct |
142 ms |
42952 KB |
Output is correct |
72 |
Correct |
124 ms |
40264 KB |
Output is correct |
73 |
Correct |
117 ms |
42436 KB |
Output is correct |
74 |
Correct |
104 ms |
45128 KB |
Output is correct |
75 |
Correct |
98 ms |
41160 KB |
Output is correct |
76 |
Correct |
129 ms |
38764 KB |
Output is correct |
77 |
Correct |
90 ms |
37700 KB |
Output is correct |
78 |
Correct |
96 ms |
37704 KB |
Output is correct |
79 |
Correct |
123 ms |
44228 KB |
Output is correct |
80 |
Correct |
97 ms |
43216 KB |
Output is correct |
81 |
Correct |
202 ms |
41860 KB |
Output is correct |
82 |
Correct |
207 ms |
41928 KB |
Output is correct |
83 |
Correct |
139 ms |
40904 KB |
Output is correct |
84 |
Correct |
89 ms |
37704 KB |
Output is correct |
85 |
Correct |
217 ms |
41984 KB |
Output is correct |
86 |
Correct |
148 ms |
44204 KB |
Output is correct |
87 |
Correct |
149 ms |
44228 KB |
Output is correct |
88 |
Correct |
112 ms |
46016 KB |
Output is correct |
89 |
Correct |
129 ms |
40976 KB |
Output is correct |
90 |
Correct |
191 ms |
43284 KB |
Output is correct |
91 |
Correct |
165 ms |
43164 KB |
Output is correct |
92 |
Correct |
210 ms |
43180 KB |
Output is correct |
93 |
Correct |
145 ms |
41672 KB |
Output is correct |
94 |
Correct |
117 ms |
39748 KB |
Output is correct |
95 |
Correct |
92 ms |
42184 KB |
Output is correct |
96 |
Correct |
85 ms |
43832 KB |
Output is correct |
97 |
Correct |
95 ms |
35292 KB |
Output is correct |
98 |
Correct |
119 ms |
38724 KB |
Output is correct |
99 |
Correct |
151 ms |
40848 KB |
Output is correct |
100 |
Correct |
41 ms |
29448 KB |
Output is correct |
101 |
Correct |
225 ms |
42948 KB |
Output is correct |
102 |
Correct |
119 ms |
39628 KB |
Output is correct |
103 |
Correct |
218 ms |
40456 KB |
Output is correct |
104 |
Correct |
221 ms |
42696 KB |
Output is correct |