#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
const int mxn=2e5,inf=1e9;
vector<ppii>e;
int val[mxn+10],n,m,pa[mxn+10],sum[mxn+10];
bool ans[mxn+10];
int find(int u){
if(pa[u]==u)return u;
int k=find(pa[u]);
ans[u]|=ans[k];
return pa[u]=k;
}
void merg(int u,int v){
int a=find(u),b=find(v);
if(a==b)return;
if(sum[b]<val[a])return void(ans[b]=true);
pa[b]=a,sum[a]+=sum[b],ans[a]|=ans[b];
}
int32_t main(){
fastio
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>val[i],sum[i]=val[i],pa[i]=i;
for(int i=0;i<m;i++){
int a,b;cin>>a>>b;
if(val[a]<val[b])swap(a,b);
e.pb({val[a],{a,b}});
}
sort(all(e));
for(auto i:e)merg(i.s.f,i.s.s);
for(int i=1;i<=n;i++)find(i),cout<<(!ans[i]);
}
Compilation message
island.cpp:35:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
35 | #pragma GCC optimize ("03,unroll-lopps")
| ^
island.cpp:41:15: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
41 | int find(int u){
| ^
island.cpp:47:22: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
47 | void merg(int u,int v){
| ^
island.cpp:53:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
53 | int32_t main(){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Incorrect |
70 ms |
13868 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
70 ms |
14092 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
74 ms |
11532 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |