Submission #604176

# Submission time Handle Problem Language Result Execution time Memory
604176 2022-07-24T19:51:49 Z DanerZein Stranded Far From Home (BOI22_island) C++14
0 / 100
1000 ms 524288 KB
#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;
int ha[MAX_N];
bool vis[MAX_N];
int n,m;
void bfs(int u){
  for(int i=0;i<n;i++) vis[i]=0;
  priority_queue<ii, vector<ii>, greater<ii> > q;
  vis[u]=1; 
  ll co=ha[u];
  for(auto &v:G[u]){
    q.push(ii(ha[v],v));
  }
  while(!q.empty()){
    int x=q.top().second; q.pop();
    if(co<ha[x]) continue;
    vis[x]=1;
    co+=ha[x];
    for(auto &v:G[x]){
      if(!vis[v]){
        q.push(ii(ha[v],v));
      }
    }
  }
}
int pa[MAX_N];
ll sb[MAX_N];
void dfs(int u,int p){
  pa[u]=p;
  sb[u]=ha[u];
  for(auto &v:G[u]){
    if(v!=p){
      dfs(v,u);
      sb[u]+=sb[v];
    }
  }
}
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);
  }
  string ans="";
  dfs(0,0);
  for(int i=0;i<n;i++){
    if(sb[i]>=ha[pa[i]]) ans+='1';
    else ans+='0';
  }
  /*for(int i=0;i<n;i++){
    bfs(i);
    bool all=1;
    for(int j=0;j<n;j++) all&=vis[j];
    if(all) ans+='1';
    else ans+='0';
    }*/
  cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Runtime error 247 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 257 ms 20280 KB Output is correct
4 Incorrect 214 ms 20084 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 304 KB Output is correct
2 Incorrect 247 ms 27448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1072 ms 246176 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 247 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -