Submission #654409

# Submission time Handle Problem Language Result Execution time Memory
654409 2022-10-31T09:02:39 Z atigun Stranded Far From Home (BOI22_island) C++14
0 / 100
324 ms 524288 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 2e3;

int n, m;
vector<ll> a(maxn+5), sum(maxn+5);
vector<vector<int>> g(maxn+5);
vector<bool> work(maxn+5), vis(maxn+5);

void dfs1(int v, int p){
  vis[v] = 1, sum[v] = a[v];
  for(int u : g[v]){
    if(u == p)
      continue;
    dfs1(u, v);
    sum[v]+= sum[u];
  }
  if(p != -1)
    work[v] = (sum[v] >= a[p]);
}

void dfs2(int v, int p){
  if(p != -1)
    work[v] = min(work[v], work[p]);
  for(int u : g[v]){
    if(u == p)
      continue;
    dfs2(u, v);
  }
}

void solve(){
  cin >> n >> m;
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs1(1, -1);
  work[1] = 1;
  dfs2(1, -1);
  for(int i = 1; i <= n; i++)
    cout << work[i];
  cout << "\n";
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt = 1;
  // cin >> tt;
  while(tt--){
    solve();
  }
}
# Verdict Execution time Memory Grader output
1 Runtime error 324 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Runtime error 5 ms 852 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 4 ms 808 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 6 ms 736 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 324 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -