답안 #654410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654410 2022-10-31T09:03:24 Z atigun Stranded Far From Home (BOI22_island) C++14
10 / 100
1000 ms 524288 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 2e5;

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();
  }
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 299 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 175 ms 22604 KB Output is correct
4 Correct 141 ms 22484 KB Output is correct
5 Correct 232 ms 14740 KB Output is correct
6 Correct 204 ms 14988 KB Output is correct
7 Correct 194 ms 14968 KB Output is correct
8 Correct 192 ms 14976 KB Output is correct
9 Correct 147 ms 14840 KB Output is correct
10 Correct 98 ms 15568 KB Output is correct
11 Correct 108 ms 15632 KB Output is correct
12 Correct 191 ms 14988 KB Output is correct
13 Correct 157 ms 33584 KB Output is correct
14 Correct 161 ms 33652 KB Output is correct
15 Correct 156 ms 33604 KB Output is correct
16 Correct 94 ms 33440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Incorrect 168 ms 33568 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8160 KB Output is correct
2 Execution timed out 1083 ms 336432 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 299 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -