Submission #1008816

# Submission time Handle Problem Language Result Execution time Memory
1008816 2024-06-26T20:11:53 Z aaaaaarroz Beech Tree (IOI23_beechtree) C++17
0 / 100
0 ms 428 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> padre;
bool menor_padre(int i, int j) {
  return padre[i] < padre[j];
}

vector<int> beechtree(int n, int m, vector<int> P, vector<int> C) {
  vector<vector<int>> graph(n, vector<int>());
  padre = P;
  for (int i = 1; i < n; i++) {
    graph[P[i]].push_back(i);
  }

  vector<int> ans(n, 0);
  for (int i = 0; i < n; i++) {
    if (i == 0) { // Manejo del caso base
      bool unico_hijo = true;
      for (int vecino : graph[i]) {
        if (padre[vecino] != i) {
          unico_hijo = false;
          break;
        }
      }
      ans[i] = unico_hijo;
      continue;
    }

    vector<int> sub;
    queue<int> cola;
    cola.push(i);
    while (!cola.empty()) {
      int nodo = cola.front();
      cola.pop();
      sub.push_back(nodo);
      for (int vecino : graph[nodo]) {
        cola.push(vecino);
      }
    }

    if (sub.size() == 1) {
      ans[i] = 1;
      continue;
    }

    sort(sub.begin() + 1, sub.end(), menor_padre);
    bool bien = true;
    map<int, int> repeticiones;
    for (int j = 1; j < sub.size(); j++) {
      int color = C[sub[j]];
      int expected_parent = sub[repeticiones[color]];

      // Verificación del padre y manejo de colores repetidos
      if (padre[sub[j]] != expected_parent || repeticiones.find(color) == repeticiones.end() ||
          repeticiones[color] > j - 1) {
        bien = false;
        break;
      }

      repeticiones[color]++;
    }

    if (bien) {
      ans[i] = 1;
    }
  }

  return ans;
}

Compilation message

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int j = 1; j < sub.size(); j++) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 428 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 428 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 428 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 428 KB 2nd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -