#include<bits/stdc++.h>
using namespace std;
long long ar[200005];
vector<int>v[200005];
int vis[200005];
int n,m;
int check(int i){
for(int x=1;x<=n;x++){
vis[x]=0;
}
priority_queue<pair<long long,int>,vector<pair<long long,int> >,greater<pair<long long,int> > >pq;
pq.push({ar[i],i});
vis[i]=1;
long long power=0;
int ck=0;
while(!pq.empty()){
long long np=pq.top().first;
int x=pq.top().second;
//cout<<x<<" "<<power<<endl;
pq.pop();
if(x==i||power>=np){
power+=np;
for(int j=0;j<v[x].size();j++){
if(vis[v[x][j]]==1){
continue;
}
vis[v[x][j]]=1;
pq.push({ar[v[x][j]],v[x][j]});
}
}else{
ck=1;
break;
}
}
if(!ck){
return 1;
}else{
return 0;
}
}
long long sum[200005];
long long mw[200005];
void dfs(int i,int p){
long long sm=ar[i];
for(int j=0;j<v[i].size();j++){
if(v[i][j]==p){
continue;
}
dfs(v[i][j],i);
sm+=sum[v[i][j]];
}
sum[i]=sm;
}
void fans(int i,int p){
if(i==1){
mw[i]=1;
}
//cout<<"i:"<<i<<endl;
for(int j=0;j<v[i].size();j++){
if(v[i][j]==p){
continue;
}
//cout<<v[i][j]<<" "<<sum[v[i][j]]<<" "<<ar[i]<<endl;
if(sum[v[i][j]]>=ar[i]){
//cout<<"work"<<endl;
mw[v[i][j]]=1;
fans(v[i][j],i);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>ar[i];
}
for(int i=1;i<=m;i++){
int a,b;
cin>>a>>b;
v[a].push_back(b);
v[b].push_back(a);
}
if(n>2000){
dfs(1,0);
fans(1,0);
/*for(int i=1;i<=n;i++){
cout<<sum[i]<<" ";
}
cout<<endl;*/
for(int i=1;i<=n;i++){
cout<<mw[i];
}
return 0;
}
for(int i=1;i<=n;i++){
cout<<check(i);
}
}
Compilation message
island.cpp: In function 'int check(int)':
island.cpp:23:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int j=0;j<v[x].size();j++){
| ~^~~~~~~~~~~~
island.cpp: In function 'void dfs(int, int)':
island.cpp:45:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int j=0;j<v[i].size();j++){
| ~^~~~~~~~~~~~
island.cpp: In function 'void fans(int, int)':
island.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int j=0;j<v[i].size();j++){
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
161 ms |
5112 KB |
Output is correct |
5 |
Correct |
138 ms |
5108 KB |
Output is correct |
6 |
Correct |
215 ms |
5104 KB |
Output is correct |
7 |
Correct |
148 ms |
5104 KB |
Output is correct |
8 |
Correct |
114 ms |
5052 KB |
Output is correct |
9 |
Correct |
213 ms |
5136 KB |
Output is correct |
10 |
Correct |
52 ms |
5076 KB |
Output is correct |
11 |
Correct |
51 ms |
5076 KB |
Output is correct |
12 |
Correct |
48 ms |
5108 KB |
Output is correct |
13 |
Correct |
98 ms |
5108 KB |
Output is correct |
14 |
Correct |
85 ms |
5108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
96 ms |
22320 KB |
Output is correct |
4 |
Correct |
96 ms |
24028 KB |
Output is correct |
5 |
Correct |
155 ms |
19984 KB |
Output is correct |
6 |
Correct |
103 ms |
20428 KB |
Output is correct |
7 |
Correct |
101 ms |
20420 KB |
Output is correct |
8 |
Correct |
123 ms |
20688 KB |
Output is correct |
9 |
Correct |
109 ms |
19556 KB |
Output is correct |
10 |
Correct |
68 ms |
18912 KB |
Output is correct |
11 |
Correct |
69 ms |
20292 KB |
Output is correct |
12 |
Correct |
113 ms |
17816 KB |
Output is correct |
13 |
Correct |
83 ms |
33172 KB |
Output is correct |
14 |
Correct |
110 ms |
33396 KB |
Output is correct |
15 |
Correct |
124 ms |
36224 KB |
Output is correct |
16 |
Correct |
80 ms |
35244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
134 ms |
31660 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Runtime error |
858 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
161 ms |
5112 KB |
Output is correct |
5 |
Correct |
138 ms |
5108 KB |
Output is correct |
6 |
Correct |
215 ms |
5104 KB |
Output is correct |
7 |
Correct |
148 ms |
5104 KB |
Output is correct |
8 |
Correct |
114 ms |
5052 KB |
Output is correct |
9 |
Correct |
213 ms |
5136 KB |
Output is correct |
10 |
Correct |
52 ms |
5076 KB |
Output is correct |
11 |
Correct |
51 ms |
5076 KB |
Output is correct |
12 |
Correct |
48 ms |
5108 KB |
Output is correct |
13 |
Correct |
98 ms |
5108 KB |
Output is correct |
14 |
Correct |
85 ms |
5108 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
96 ms |
22320 KB |
Output is correct |
18 |
Correct |
96 ms |
24028 KB |
Output is correct |
19 |
Correct |
155 ms |
19984 KB |
Output is correct |
20 |
Correct |
103 ms |
20428 KB |
Output is correct |
21 |
Correct |
101 ms |
20420 KB |
Output is correct |
22 |
Correct |
123 ms |
20688 KB |
Output is correct |
23 |
Correct |
109 ms |
19556 KB |
Output is correct |
24 |
Correct |
68 ms |
18912 KB |
Output is correct |
25 |
Correct |
69 ms |
20292 KB |
Output is correct |
26 |
Correct |
113 ms |
17816 KB |
Output is correct |
27 |
Correct |
83 ms |
33172 KB |
Output is correct |
28 |
Correct |
110 ms |
33396 KB |
Output is correct |
29 |
Correct |
124 ms |
36224 KB |
Output is correct |
30 |
Correct |
80 ms |
35244 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Incorrect |
134 ms |
31660 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |