이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
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++){
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |