#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int n,m;
cin>>n>>m;
int val[n+1];
for(int i=1;i<=n;i++)cin>>val[i];
vector<int>vct[n+1];
while(m--){
int x,y;
cin>>x>>y;
vct[x].push_back(y);
vct[y].push_back(x);
}
string s(n+1,'1');
vector<bool>done(n+1);
srand(43654634);
vector<pair<int,int>>vv,V;
for(int i=1;i<=n;i++)V.push_back({val[i],i});
for(auto &[ii,i]:V){
if(done[i])continue;
vector<int>v;
vector<bool>vis(n+1);
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
pq.push({0,i});
int tot=0;
bool bl=1;
while(pq.size()){
int a=pq.top().second,b=pq.top().first;
pq.pop();
if(vis[a])continue;
vis[a]=1;
if(b>tot)break;
v.push_back(a);
tot+=val[a];
for(auto &w:vct[a]){
pq.push({val[w],w});
}
}
if(v.size()==n){
deque<pair<int,int>>dq={{i,val[i]}};
for(auto &w:v)vis[w]=0;
while(dq.size()){
int a=dq.front().first,b=dq.front().second;
dq.pop_front();
if(vis[a])continue;
vis[a]=1;
if(val[a]>=b){
done[a]=1;
s[a]='1';
b=val[a];
}
for(auto &w:vct[a]){
dq.push_back({w,b});
}
}
}else{
for(auto &i:v){
done[i]=1;
s[i]='0';
}
}
}
cout<<s.substr(1,n);
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:41:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
41 | if(v.size()==n){
| ~~~~~~~~^~~
island.cpp:28:14: warning: unused variable 'bl' [-Wunused-variable]
28 | bool bl=1;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
102 ms |
512 KB |
Output is correct |
5 |
Correct |
123 ms |
492 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
137 ms |
508 KB |
Output is correct |
8 |
Correct |
72 ms |
476 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
112 ms |
468 KB |
Output is correct |
11 |
Correct |
101 ms |
468 KB |
Output is correct |
12 |
Correct |
189 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
496 KB |
Output is correct |
14 |
Correct |
7 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
1076 ms |
22892 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1084 ms |
19916 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1069 ms |
20988 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
102 ms |
512 KB |
Output is correct |
5 |
Correct |
123 ms |
492 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
137 ms |
508 KB |
Output is correct |
8 |
Correct |
72 ms |
476 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
112 ms |
468 KB |
Output is correct |
11 |
Correct |
101 ms |
468 KB |
Output is correct |
12 |
Correct |
189 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
496 KB |
Output is correct |
14 |
Correct |
7 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
1076 ms |
22892 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |