#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
//------------------------------DEFINE------------------------------
//******************************************************************
#define IOS ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0)
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//******************************************************************
//----------------------------FUNCTION------------------------------
//******************************************************************
ll gcd(ll a,ll b){
if(a>b) swap(a,b);
if(a==0) return a+b;
return gcd(b%a,a);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
bool is_prime(ll n){
ll k=sqrt(n);
if(n==2) return true;
if(n<2||n%2==0||k*k==n) return false;
for(int i=3;i<=k;i+=2){
if(n%i==0){
return false;
}
}
return true;
}
//*****************************************************************
//--------------------------MAIN-CODE------------------------------
const int mxn=2e5+5;
ll t=1,n,m,arr[mxn],p[mxn],sum[mxn],ans[mxn];
vector<int>vt[mxn];
vector<int>good[mxn];
int fnd(int u){
if(p[u]==u) return u;
return p[u]=fnd(p[u]);
}
void Union(int u,int v){
u=fnd(u);
v=fnd(v);
if(u!=v){
if(good[v].size()>good[u].size()) swap(u,v);
sum[u]+=sum[v];
p[v]=u;
for(int x:good[v]){
good[u].pb(x);
}
}
}
bool cmp(int x,int y){
return arr[x]<arr[y];
}
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>arr[i];
}
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
vt[x].pb(y);
vt[y].pb(x);
}
for(int i=1;i<=n;i++){
sort(all(vt[i]),cmp);
p[i]=i;
sum[i]=arr[i];
good[i].pb(i);
}
vector<int>idx(n);
iota(all(idx),1);
sort(all(idx),cmp);
for(int i=0;i<idx.size();i++){
int u=idx[i];
for(int v:vt[u]){
if(arr[v]>arr[u]) break;
if(sum[fnd(v)]<arr[u]){
good[fnd(v)].clear();
}
Union(u,v);
}
}
int node=idx.back();
for(int x:good[fnd(node)]){
ans[x]=1;
}
for(int i=1;i<=n;i++){
cout<<ans[i];
}
cout<<endl;
}
int main(){
IOS;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Compilation message
island.cpp: In function 'void solve()':
island.cpp:88:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int i=0;i<idx.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9732 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9940 KB |
Output is correct |
5 |
Correct |
6 ms |
9940 KB |
Output is correct |
6 |
Correct |
8 ms |
10004 KB |
Output is correct |
7 |
Correct |
6 ms |
9916 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
7 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9940 KB |
Output is correct |
11 |
Correct |
9 ms |
10000 KB |
Output is correct |
12 |
Correct |
6 ms |
10004 KB |
Output is correct |
13 |
Correct |
6 ms |
9872 KB |
Output is correct |
14 |
Correct |
6 ms |
9900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9672 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
160 ms |
34648 KB |
Output is correct |
4 |
Correct |
151 ms |
35080 KB |
Output is correct |
5 |
Correct |
150 ms |
35748 KB |
Output is correct |
6 |
Correct |
162 ms |
36480 KB |
Output is correct |
7 |
Correct |
180 ms |
36512 KB |
Output is correct |
8 |
Correct |
192 ms |
36456 KB |
Output is correct |
9 |
Correct |
120 ms |
37280 KB |
Output is correct |
10 |
Correct |
98 ms |
32184 KB |
Output is correct |
11 |
Correct |
129 ms |
34500 KB |
Output is correct |
12 |
Correct |
172 ms |
32944 KB |
Output is correct |
13 |
Correct |
116 ms |
35200 KB |
Output is correct |
14 |
Correct |
164 ms |
35152 KB |
Output is correct |
15 |
Correct |
153 ms |
34852 KB |
Output is correct |
16 |
Correct |
81 ms |
33908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
155 ms |
37424 KB |
Output is correct |
3 |
Correct |
185 ms |
37536 KB |
Output is correct |
4 |
Correct |
124 ms |
38344 KB |
Output is correct |
5 |
Correct |
135 ms |
35320 KB |
Output is correct |
6 |
Correct |
240 ms |
37608 KB |
Output is correct |
7 |
Correct |
127 ms |
34780 KB |
Output is correct |
8 |
Correct |
120 ms |
34852 KB |
Output is correct |
9 |
Correct |
80 ms |
33844 KB |
Output is correct |
10 |
Correct |
157 ms |
35232 KB |
Output is correct |
11 |
Correct |
156 ms |
34388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
192 ms |
35360 KB |
Output is correct |
3 |
Correct |
215 ms |
35824 KB |
Output is correct |
4 |
Correct |
160 ms |
36756 KB |
Output is correct |
5 |
Correct |
186 ms |
37516 KB |
Output is correct |
6 |
Correct |
179 ms |
35148 KB |
Output is correct |
7 |
Correct |
128 ms |
35524 KB |
Output is correct |
8 |
Correct |
93 ms |
34680 KB |
Output is correct |
9 |
Correct |
87 ms |
23836 KB |
Output is correct |
10 |
Correct |
220 ms |
35192 KB |
Output is correct |
11 |
Correct |
156 ms |
34520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9732 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9940 KB |
Output is correct |
5 |
Correct |
6 ms |
9940 KB |
Output is correct |
6 |
Correct |
8 ms |
10004 KB |
Output is correct |
7 |
Correct |
6 ms |
9916 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
7 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9940 KB |
Output is correct |
11 |
Correct |
9 ms |
10000 KB |
Output is correct |
12 |
Correct |
6 ms |
10004 KB |
Output is correct |
13 |
Correct |
6 ms |
9872 KB |
Output is correct |
14 |
Correct |
6 ms |
9900 KB |
Output is correct |
15 |
Correct |
6 ms |
9672 KB |
Output is correct |
16 |
Correct |
6 ms |
9684 KB |
Output is correct |
17 |
Correct |
160 ms |
34648 KB |
Output is correct |
18 |
Correct |
151 ms |
35080 KB |
Output is correct |
19 |
Correct |
150 ms |
35748 KB |
Output is correct |
20 |
Correct |
162 ms |
36480 KB |
Output is correct |
21 |
Correct |
180 ms |
36512 KB |
Output is correct |
22 |
Correct |
192 ms |
36456 KB |
Output is correct |
23 |
Correct |
120 ms |
37280 KB |
Output is correct |
24 |
Correct |
98 ms |
32184 KB |
Output is correct |
25 |
Correct |
129 ms |
34500 KB |
Output is correct |
26 |
Correct |
172 ms |
32944 KB |
Output is correct |
27 |
Correct |
116 ms |
35200 KB |
Output is correct |
28 |
Correct |
164 ms |
35152 KB |
Output is correct |
29 |
Correct |
153 ms |
34852 KB |
Output is correct |
30 |
Correct |
81 ms |
33908 KB |
Output is correct |
31 |
Correct |
6 ms |
9684 KB |
Output is correct |
32 |
Correct |
155 ms |
37424 KB |
Output is correct |
33 |
Correct |
185 ms |
37536 KB |
Output is correct |
34 |
Correct |
124 ms |
38344 KB |
Output is correct |
35 |
Correct |
135 ms |
35320 KB |
Output is correct |
36 |
Correct |
240 ms |
37608 KB |
Output is correct |
37 |
Correct |
127 ms |
34780 KB |
Output is correct |
38 |
Correct |
120 ms |
34852 KB |
Output is correct |
39 |
Correct |
80 ms |
33844 KB |
Output is correct |
40 |
Correct |
157 ms |
35232 KB |
Output is correct |
41 |
Correct |
156 ms |
34388 KB |
Output is correct |
42 |
Correct |
7 ms |
9684 KB |
Output is correct |
43 |
Correct |
192 ms |
35360 KB |
Output is correct |
44 |
Correct |
215 ms |
35824 KB |
Output is correct |
45 |
Correct |
160 ms |
36756 KB |
Output is correct |
46 |
Correct |
186 ms |
37516 KB |
Output is correct |
47 |
Correct |
179 ms |
35148 KB |
Output is correct |
48 |
Correct |
128 ms |
35524 KB |
Output is correct |
49 |
Correct |
93 ms |
34680 KB |
Output is correct |
50 |
Correct |
87 ms |
23836 KB |
Output is correct |
51 |
Correct |
220 ms |
35192 KB |
Output is correct |
52 |
Correct |
156 ms |
34520 KB |
Output is correct |
53 |
Correct |
6 ms |
9684 KB |
Output is correct |
54 |
Correct |
7 ms |
9684 KB |
Output is correct |
55 |
Correct |
6 ms |
9736 KB |
Output is correct |
56 |
Correct |
8 ms |
9940 KB |
Output is correct |
57 |
Correct |
6 ms |
9912 KB |
Output is correct |
58 |
Correct |
8 ms |
9940 KB |
Output is correct |
59 |
Correct |
6 ms |
9940 KB |
Output is correct |
60 |
Correct |
6 ms |
9868 KB |
Output is correct |
61 |
Correct |
7 ms |
9872 KB |
Output is correct |
62 |
Correct |
6 ms |
9940 KB |
Output is correct |
63 |
Correct |
6 ms |
9940 KB |
Output is correct |
64 |
Correct |
5 ms |
9940 KB |
Output is correct |
65 |
Correct |
5 ms |
9940 KB |
Output is correct |
66 |
Correct |
5 ms |
9908 KB |
Output is correct |
67 |
Correct |
104 ms |
34704 KB |
Output is correct |
68 |
Correct |
176 ms |
35072 KB |
Output is correct |
69 |
Correct |
172 ms |
35908 KB |
Output is correct |
70 |
Correct |
133 ms |
36572 KB |
Output is correct |
71 |
Correct |
167 ms |
36508 KB |
Output is correct |
72 |
Correct |
212 ms |
36436 KB |
Output is correct |
73 |
Correct |
103 ms |
37284 KB |
Output is correct |
74 |
Correct |
106 ms |
32216 KB |
Output is correct |
75 |
Correct |
122 ms |
34536 KB |
Output is correct |
76 |
Correct |
188 ms |
32880 KB |
Output is correct |
77 |
Correct |
109 ms |
35236 KB |
Output is correct |
78 |
Correct |
174 ms |
35196 KB |
Output is correct |
79 |
Correct |
99 ms |
34764 KB |
Output is correct |
80 |
Correct |
87 ms |
34076 KB |
Output is correct |
81 |
Correct |
200 ms |
37400 KB |
Output is correct |
82 |
Correct |
182 ms |
37460 KB |
Output is correct |
83 |
Correct |
114 ms |
38384 KB |
Output is correct |
84 |
Correct |
117 ms |
35320 KB |
Output is correct |
85 |
Correct |
166 ms |
37552 KB |
Output is correct |
86 |
Correct |
144 ms |
34792 KB |
Output is correct |
87 |
Correct |
185 ms |
34792 KB |
Output is correct |
88 |
Correct |
116 ms |
35256 KB |
Output is correct |
89 |
Correct |
174 ms |
34308 KB |
Output is correct |
90 |
Correct |
188 ms |
35244 KB |
Output is correct |
91 |
Correct |
153 ms |
35904 KB |
Output is correct |
92 |
Correct |
198 ms |
36672 KB |
Output is correct |
93 |
Correct |
235 ms |
37488 KB |
Output is correct |
94 |
Correct |
213 ms |
35152 KB |
Output is correct |
95 |
Correct |
125 ms |
35568 KB |
Output is correct |
96 |
Correct |
92 ms |
34628 KB |
Output is correct |
97 |
Correct |
106 ms |
23856 KB |
Output is correct |
98 |
Correct |
189 ms |
35232 KB |
Output is correct |
99 |
Correct |
171 ms |
34452 KB |
Output is correct |
100 |
Correct |
47 ms |
13980 KB |
Output is correct |
101 |
Correct |
191 ms |
35964 KB |
Output is correct |
102 |
Correct |
178 ms |
30592 KB |
Output is correct |
103 |
Correct |
177 ms |
31092 KB |
Output is correct |
104 |
Correct |
184 ms |
34696 KB |
Output is correct |