Submission #604243

#TimeUsernameProblemLanguageResultExecution timeMemory
604243DanerZeinStranded Far From Home (BOI22_island)C++14
40 / 100
1084 ms30904 KiB
#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(){ 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 (stderr)

island.cpp: In function 'int main()':
island.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(int h=1;h<dh.size();h++){
      |               ~^~~~~~~~~~
island.cpp:61:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int j=0;j<cma.size();j++){
      |              ~^~~~~~~~~~~
island.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int j=0;j<con.size();j++){
      |              ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...