#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<int>vv,V;
for(int i=1;i<=n;i++)vv.push_back(i);
while(vv.size()){
swap(vv.back(),vv[rand()%vv.size()]);
V.push_back(vv.back());
vv.pop_back();
}
for(auto &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:46: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]
46 | if(v.size()==n){
| ~~~~~~~~^~~
island.cpp:33:14: warning: unused variable 'bl' [-Wunused-variable]
33 | bool bl=1;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
103 ms |
512 KB |
Output is correct |
5 |
Correct |
125 ms |
496 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
111 ms |
516 KB |
Output is correct |
8 |
Correct |
70 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
104 ms |
500 KB |
Output is correct |
11 |
Correct |
94 ms |
504 KB |
Output is correct |
12 |
Correct |
116 ms |
544 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
1084 ms |
22764 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1085 ms |
19932 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1084 ms |
20916 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
103 ms |
512 KB |
Output is correct |
5 |
Correct |
125 ms |
496 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
111 ms |
516 KB |
Output is correct |
8 |
Correct |
70 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
104 ms |
500 KB |
Output is correct |
11 |
Correct |
94 ms |
504 KB |
Output is correct |
12 |
Correct |
116 ms |
544 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
6 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 |
1084 ms |
22764 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |