/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
cout<<(x?"YES":"NO")<<endl;
}
const int N=2e5+5;
int ans[N],arr[N],n,m;
vector<int>adj[N];
struct DSU{
vector<ll>P,sz,sum;
vector<vector<int>>ok;
void init(int n){
P.resize(n+5);
ok.resize(n+5);
sum.resize(n+5);
sz.resize(n+5);
for(int i=0;i<n+5;i++)sz[i]=1,sum[i]=arr[i],P[i]=i,ok[i].push_back(i);
}
int find(int node){
if(P[node]==node)return node;
return P[node]=find(P[node]);
}
bool unite(int a,int b){
int p1=find(a);
int p2=find(b);
if(p1==p2){
return 0;
}
if(sz[p1]<sz[p2])swap(p1,p2);
for(auto i:ok[p2])ok[p1].push_back(i);
ok[p2].clear();
P[p2]=p1;
sum[p1]+=sum[p2];
sz[p1]+=sz[p2];
return 1;
}
}d;
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
#ifndef ONLINE_JUDGE
//freopen("input.in", "r", stdin);
// freopen("output.out", "w", stdout);
#endif
fast
cin>>n>>m;
vector<pair<int,int>>v;
for(int i=1;i<=n;i++){
cin>>arr[i];ans[i]=1;
v.push_back({arr[i],i});
}
while(m--){
int u,v;cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
d.init(n);
sort(all(v));
for(int i=0;i<n;i++){
int node=v[i].second,x=v[i].first;
for(auto ch:adj[node]){
if(arr[ch]>arr[node] || (arr[ch]==arr[node] && ch>node))continue;
if(d.sum[d.find(ch)]<arr[node]){
for(auto j:d.ok[d.find(ch)])ans[j]=0;
d.ok[d.find(ch)].clear();
}
d.unite(node,ch);
}
}
for(int i=1;i<=n;i++){
cout<<ans[i];
}
cout<<endl;
return 0;
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:93:30: warning: unused variable 'x' [-Wunused-variable]
93 | int node=v[i].second,x=v[i].first;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
2 ms |
5212 KB |
Output is correct |
7 |
Correct |
2 ms |
5464 KB |
Output is correct |
8 |
Correct |
2 ms |
5212 KB |
Output is correct |
9 |
Correct |
2 ms |
5212 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
2 ms |
5464 KB |
Output is correct |
12 |
Correct |
2 ms |
5212 KB |
Output is correct |
13 |
Correct |
2 ms |
5212 KB |
Output is correct |
14 |
Correct |
3 ms |
5420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
105 ms |
31768 KB |
Output is correct |
4 |
Correct |
103 ms |
35016 KB |
Output is correct |
5 |
Correct |
134 ms |
36960 KB |
Output is correct |
6 |
Correct |
153 ms |
38052 KB |
Output is correct |
7 |
Correct |
138 ms |
38088 KB |
Output is correct |
8 |
Correct |
111 ms |
36508 KB |
Output is correct |
9 |
Correct |
111 ms |
39128 KB |
Output is correct |
10 |
Correct |
128 ms |
34564 KB |
Output is correct |
11 |
Correct |
130 ms |
36288 KB |
Output is correct |
12 |
Correct |
122 ms |
34504 KB |
Output is correct |
13 |
Correct |
98 ms |
35016 KB |
Output is correct |
14 |
Correct |
103 ms |
35528 KB |
Output is correct |
15 |
Correct |
108 ms |
36552 KB |
Output is correct |
16 |
Correct |
79 ms |
35440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
165 ms |
34156 KB |
Output is correct |
3 |
Correct |
165 ms |
34372 KB |
Output is correct |
4 |
Correct |
122 ms |
36548 KB |
Output is correct |
5 |
Correct |
100 ms |
34756 KB |
Output is correct |
6 |
Correct |
166 ms |
38856 KB |
Output is correct |
7 |
Correct |
115 ms |
36480 KB |
Output is correct |
8 |
Correct |
129 ms |
36496 KB |
Output is correct |
9 |
Correct |
87 ms |
35656 KB |
Output is correct |
10 |
Correct |
118 ms |
34948 KB |
Output is correct |
11 |
Correct |
121 ms |
34708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
182 ms |
32148 KB |
Output is correct |
3 |
Correct |
179 ms |
36888 KB |
Output is correct |
4 |
Correct |
191 ms |
38084 KB |
Output is correct |
5 |
Correct |
155 ms |
39112 KB |
Output is correct |
6 |
Correct |
131 ms |
36236 KB |
Output is correct |
7 |
Correct |
102 ms |
37356 KB |
Output is correct |
8 |
Correct |
80 ms |
34392 KB |
Output is correct |
9 |
Correct |
82 ms |
21820 KB |
Output is correct |
10 |
Correct |
128 ms |
38576 KB |
Output is correct |
11 |
Correct |
127 ms |
35028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
2 ms |
5212 KB |
Output is correct |
7 |
Correct |
2 ms |
5464 KB |
Output is correct |
8 |
Correct |
2 ms |
5212 KB |
Output is correct |
9 |
Correct |
2 ms |
5212 KB |
Output is correct |
10 |
Correct |
2 ms |
5212 KB |
Output is correct |
11 |
Correct |
2 ms |
5464 KB |
Output is correct |
12 |
Correct |
2 ms |
5212 KB |
Output is correct |
13 |
Correct |
2 ms |
5212 KB |
Output is correct |
14 |
Correct |
3 ms |
5420 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
1 ms |
4956 KB |
Output is correct |
17 |
Correct |
105 ms |
31768 KB |
Output is correct |
18 |
Correct |
103 ms |
35016 KB |
Output is correct |
19 |
Correct |
134 ms |
36960 KB |
Output is correct |
20 |
Correct |
153 ms |
38052 KB |
Output is correct |
21 |
Correct |
138 ms |
38088 KB |
Output is correct |
22 |
Correct |
111 ms |
36508 KB |
Output is correct |
23 |
Correct |
111 ms |
39128 KB |
Output is correct |
24 |
Correct |
128 ms |
34564 KB |
Output is correct |
25 |
Correct |
130 ms |
36288 KB |
Output is correct |
26 |
Correct |
122 ms |
34504 KB |
Output is correct |
27 |
Correct |
98 ms |
35016 KB |
Output is correct |
28 |
Correct |
103 ms |
35528 KB |
Output is correct |
29 |
Correct |
108 ms |
36552 KB |
Output is correct |
30 |
Correct |
79 ms |
35440 KB |
Output is correct |
31 |
Correct |
1 ms |
4952 KB |
Output is correct |
32 |
Correct |
165 ms |
34156 KB |
Output is correct |
33 |
Correct |
165 ms |
34372 KB |
Output is correct |
34 |
Correct |
122 ms |
36548 KB |
Output is correct |
35 |
Correct |
100 ms |
34756 KB |
Output is correct |
36 |
Correct |
166 ms |
38856 KB |
Output is correct |
37 |
Correct |
115 ms |
36480 KB |
Output is correct |
38 |
Correct |
129 ms |
36496 KB |
Output is correct |
39 |
Correct |
87 ms |
35656 KB |
Output is correct |
40 |
Correct |
118 ms |
34948 KB |
Output is correct |
41 |
Correct |
121 ms |
34708 KB |
Output is correct |
42 |
Correct |
1 ms |
4956 KB |
Output is correct |
43 |
Correct |
182 ms |
32148 KB |
Output is correct |
44 |
Correct |
179 ms |
36888 KB |
Output is correct |
45 |
Correct |
191 ms |
38084 KB |
Output is correct |
46 |
Correct |
155 ms |
39112 KB |
Output is correct |
47 |
Correct |
131 ms |
36236 KB |
Output is correct |
48 |
Correct |
102 ms |
37356 KB |
Output is correct |
49 |
Correct |
80 ms |
34392 KB |
Output is correct |
50 |
Correct |
82 ms |
21820 KB |
Output is correct |
51 |
Correct |
128 ms |
38576 KB |
Output is correct |
52 |
Correct |
127 ms |
35028 KB |
Output is correct |
53 |
Correct |
1 ms |
4956 KB |
Output is correct |
54 |
Correct |
1 ms |
4956 KB |
Output is correct |
55 |
Correct |
1 ms |
4956 KB |
Output is correct |
56 |
Correct |
2 ms |
5208 KB |
Output is correct |
57 |
Correct |
2 ms |
5468 KB |
Output is correct |
58 |
Correct |
2 ms |
5212 KB |
Output is correct |
59 |
Correct |
2 ms |
5212 KB |
Output is correct |
60 |
Correct |
2 ms |
5464 KB |
Output is correct |
61 |
Correct |
2 ms |
5212 KB |
Output is correct |
62 |
Correct |
2 ms |
5468 KB |
Output is correct |
63 |
Correct |
2 ms |
5468 KB |
Output is correct |
64 |
Correct |
3 ms |
5464 KB |
Output is correct |
65 |
Correct |
2 ms |
5208 KB |
Output is correct |
66 |
Correct |
2 ms |
5432 KB |
Output is correct |
67 |
Correct |
109 ms |
36220 KB |
Output is correct |
68 |
Correct |
99 ms |
35020 KB |
Output is correct |
69 |
Correct |
133 ms |
36896 KB |
Output is correct |
70 |
Correct |
146 ms |
38612 KB |
Output is correct |
71 |
Correct |
148 ms |
38044 KB |
Output is correct |
72 |
Correct |
110 ms |
36548 KB |
Output is correct |
73 |
Correct |
107 ms |
39120 KB |
Output is correct |
74 |
Correct |
119 ms |
34608 KB |
Output is correct |
75 |
Correct |
108 ms |
36288 KB |
Output is correct |
76 |
Correct |
120 ms |
34620 KB |
Output is correct |
77 |
Correct |
96 ms |
35016 KB |
Output is correct |
78 |
Correct |
98 ms |
35204 KB |
Output is correct |
79 |
Correct |
104 ms |
36540 KB |
Output is correct |
80 |
Correct |
87 ms |
35588 KB |
Output is correct |
81 |
Correct |
160 ms |
38776 KB |
Output is correct |
82 |
Correct |
168 ms |
38936 KB |
Output is correct |
83 |
Correct |
118 ms |
36472 KB |
Output is correct |
84 |
Correct |
100 ms |
34844 KB |
Output is correct |
85 |
Correct |
159 ms |
38800 KB |
Output is correct |
86 |
Correct |
138 ms |
36524 KB |
Output is correct |
87 |
Correct |
114 ms |
36464 KB |
Output is correct |
88 |
Correct |
99 ms |
34904 KB |
Output is correct |
89 |
Correct |
123 ms |
34760 KB |
Output is correct |
90 |
Correct |
179 ms |
36936 KB |
Output is correct |
91 |
Correct |
167 ms |
36804 KB |
Output is correct |
92 |
Correct |
170 ms |
38044 KB |
Output is correct |
93 |
Correct |
162 ms |
39624 KB |
Output is correct |
94 |
Correct |
125 ms |
36212 KB |
Output is correct |
95 |
Correct |
104 ms |
37192 KB |
Output is correct |
96 |
Correct |
81 ms |
34500 KB |
Output is correct |
97 |
Correct |
90 ms |
21940 KB |
Output is correct |
98 |
Correct |
132 ms |
38600 KB |
Output is correct |
99 |
Correct |
120 ms |
34704 KB |
Output is correct |
100 |
Correct |
31 ms |
9560 KB |
Output is correct |
101 |
Correct |
171 ms |
37204 KB |
Output is correct |
102 |
Correct |
116 ms |
30856 KB |
Output is correct |
103 |
Correct |
153 ms |
31396 KB |
Output is correct |
104 |
Correct |
188 ms |
35820 KB |
Output is correct |