# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1008813 | 2024-06-26T20:04:17 Z | aaaaaarroz | 참나무 (IOI23_beechtree) | C++17 | 1 ms | 348 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); padre = P; // Construir el árbol for (int i = 1; i < n; i++) { graph[P[i]].push_back(i); } vector<int> ans(n, 0); // Evaluar cada nodo r como raíz del subárbol for (int r = 0; r < n; r++) { vector<int> sub; queue<int> cola; cola.push(r); // Recorrer el subárbol T(r) while (!cola.empty()) { int nodo = cola.front(); cola.pop(); sub.push_back(nodo); for (int vecino : graph[nodo]) { cola.push(vecino); } } // Verificar si el subárbol es bonito // Usamos un vector para llevar la cuenta de la última aparición del color vector<int> last_occurrence(m + 1, -1); bool bien = true; for (int i = 0; i < sub.size(); i++) { int nodo = sub[i]; int color = C[nodo]; if (last_occurrence[color] != -1) { int expected_parent = sub[last_occurrence[color]]; if (P[nodo] != expected_parent) { bien = false; break; } } last_occurrence[color] = i; } if (bien) { ans[r] = 1; } } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | 2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 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 | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 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 | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Incorrect | 0 ms | 348 KB | 2nd lines differ - on the 1st token, expected: '1', found: '0' |
10 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 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 | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | 2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 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 | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | 2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 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 | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | 2nd lines differ - on the 2nd token, expected: '1', found: '0' |
3 | Halted | 0 ms | 0 KB | - |