Submission #647419

# Submission time Handle Problem Language Result Execution time Memory
647419 2022-10-02T13:53:07 Z Pety Stranded Far From Home (BOI22_island) C++14
0 / 100
285 ms 34964 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int INF = 1e9;
const int MOD = 1e9 + 7;

int n, m, val[200002], ind[200002], p[200002], ok[200002], sz[200002];
vector<int>G2[200002];
vector<int>G[200002];


int find (int x) {
  if (p[x] == x)
    return x;
  return p[x] = find(p[x]); 
}

void Union (int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    G[a].push_back(b);
    p[b] = a;
  }
}

bool cmp (int a, int b) {
  return val[a] < val[b];
}

void dfs (int nod, int par) {
  sz[nod] = val[nod];
  for (auto it : G[nod]) {
    if (it == par)
      continue;
    dfs(it, nod);
    sz[nod] += sz[it];
  }
  ok[nod] = (sz[nod] >= val[par]);
}

void dfs2 (int nod, int par, bool idk) {
  for (auto it : G[nod]) {
    if (it == par)
      continue;
    dfs2(it, nod, (idk & ok[it]));
  }
  ok[nod] = idk;
}

int main () 
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) 
    cin >> val[i];
  for (int i = 1; i <= m; i++) {  
    int x, y;
    cin >> x >> y;
    G2[x].push_back(y);
    G2[y].push_back(x);
  }
  for (int i = 1; i <= n; i++)
    ind[i] = p[i] = i;
  sort(ind + 1, ind + n + 1, cmp);  
  for (int i = 1; i <= n; i++)
    for (auto it : G2[ind[i]])
      if (val[it] <= val[ind[i]])
        Union(ind[i], it);
  dfs(find(1), 0);
  dfs2(find(1), 0, 1);
  for (int i = 1; i <= n; i++)
    cout << ok[i];
  return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Incorrect 7 ms 9868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9732 KB Output is correct
2 Correct 5 ms 9724 KB Output is correct
3 Incorrect 171 ms 34964 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 217 ms 28576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9636 KB Output is correct
2 Incorrect 285 ms 29104 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Incorrect 7 ms 9868 KB Output isn't correct
5 Halted 0 ms 0 KB -