#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
const int MAX_N=2e5+10;
vector<vi> G;
ll ha[MAX_N];
bool vis[MAX_N];
bool ans[MAX_N];
int n,m;
vector<int> cma;
vector<int> con;
ll dfs(int u,int ma){
if(ma==ha[u])
con.push_back(u);
vis[u]=1;
ll s=ha[u];
for(auto &v:G[u]){
if(ma<ha[v]){
cma.push_back(v);
}
else{
if(!vis[v]){
s+=dfs(v,ma);
}
}
}
return s;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin>>n>>m;
G.resize(n+1);
for(int i=0;i<n;i++) cin>>ha[i];
for(int i=0;i<m;i++){
int a,b; cin>>a>>b;
a--; b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<int> dh;
for(int i=0;i<n;i++){
dh.push_back(ha[i]);
}
sort(dh.begin(),dh.end());
dh.erase(unique(dh.begin(),dh.end()),dh.end());
reverse(dh.begin(),dh.end());
for(int i=0;i<n;i++){
if(ha[i]==dh[0])
ans[i]=1;
}
for(int h=1;h<dh.size();h++){
int v=dh[h];
memset(vis,0,sizeof vis);
for(int i=0;i<n;i++){
if(!vis[i] && ha[i]==v){
con.clear();
cma.clear();
ll s=dfs(i,v);
bool ok=0;
for(int j=0;j<cma.size();j++){
if(s>=ha[cma[j]])
ok|=ans[cma[j]];
}
for(int j=0;j<con.size();j++){
ans[con[j]]=ok;
}
}
}
}
string pr="";
for(int i=0;i<n;i++){
if(ans[i]) pr+='1';
else pr+='0';
}
cout<<pr<<endl;
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:54:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int h=1;h<dh.size();h++){
| ~^~~~~~~~~~
island.cpp:63:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int j=0;j<cma.size();j++){
| ~^~~~~~~~~~~
island.cpp:67:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int j=0;j<con.size();j++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
29 ms |
692 KB |
Output is correct |
5 |
Correct |
14 ms |
676 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
24 ms |
724 KB |
Output is correct |
8 |
Correct |
23 ms |
676 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
11 ms |
724 KB |
Output is correct |
11 |
Correct |
16 ms |
732 KB |
Output is correct |
12 |
Correct |
11 ms |
664 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
1092 ms |
20192 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 |
1095 ms |
21228 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
200 ms |
14628 KB |
Output is correct |
3 |
Correct |
191 ms |
14528 KB |
Output is correct |
4 |
Correct |
211 ms |
14596 KB |
Output is correct |
5 |
Correct |
109 ms |
14668 KB |
Output is correct |
6 |
Correct |
97 ms |
13780 KB |
Output is correct |
7 |
Correct |
83 ms |
16132 KB |
Output is correct |
8 |
Correct |
76 ms |
23320 KB |
Output is correct |
9 |
Correct |
98 ms |
8900 KB |
Output is correct |
10 |
Correct |
121 ms |
15520 KB |
Output is correct |
11 |
Correct |
173 ms |
28908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
29 ms |
692 KB |
Output is correct |
5 |
Correct |
14 ms |
676 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
24 ms |
724 KB |
Output is correct |
8 |
Correct |
23 ms |
676 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
11 ms |
724 KB |
Output is correct |
11 |
Correct |
16 ms |
732 KB |
Output is correct |
12 |
Correct |
11 ms |
664 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
1092 ms |
20192 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |