목록트리 (32)
넘치게 채우기
https://www.acmicpc.net/problem/17501BOJ - 수식 트리문제 유형: 트리, 그래프, 그리디, 정렬문제 난이도: Gold II시간 제한: 1초메모리 제한: 256MB 문제수식 트리는 루트가 있는 이진 트리로 2N-1개의 노드가 있습니다. 1번부터 N번까지 노드는 피연산자 노드이며 다른 노드들은 연산자 노드이고 2N-1번 노드가 루트입니다.연산자 노드는 항상 두 개의 자식 노드를 가지며 연산자로 '+' 또는 '-' 를 가집니다.피연산자 노드는 아무 자식도 가지지 않고 하나의 정수를 가집니다.수식 트리의 계산은 다음과 같이 진행됩니다.2개의 피연산자 노드를 자식으로 가지는 연산자 노드를 하나 선택합니다.해당 노드의 연산자가 '+' 인 경우, 연산자 노드를 피연산자 노드로 바꾸고 ..
https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/description/leetcode - Construct Binary Tree from Preorder and Postorder Traversal문제 유형: 트리, 분할 정복문제 난이도: Medium 문제Given two integer arrays, preorder and postorder where preorder is the preorder traversal of a binary tree of distinct values and postorder is the postorder traversal of the same tree, reconstr..
https://leetcode.com/problems/recover-a-tree-from-preorder-traversal/description/leetcode - Recover a Tree From Preorder Traversal문제 유형: 스택, 트리, dfs, 문자열 처리문제 난이도: Hard 문제We run a preorder depth-first search (DFS) on the root of a binary tree.At each node in this traversal, we output D dashes (where D is the depth of this node), then we output the value of this node. If the depth of a node is D..
https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree/description/?envType=daily-question&envId=2025-02-21leetcode - Find Elements in a Contaminated Binary Tree문제 유형: 트리, 해시문제 난이도: Medium 문제Given a binary tree with the following rules:root.val == 0For any treeNode:If treeNode.val has a value x and treeNode.left != null, then treeNode.left.val == 2 * x + 1If treeNode.val has a..

https://www.acmicpc.net/problem/2263BOJ - 트리의 순회문제 유형: 트리, dfs, 분할 정복문제 난이도: Gold I시간 제한: 5초메모리 제한: 128MB 문제n개의 정점을 갖는 이진 트리의 정점에 1부터 n까지의 번호가 중복 없이 매겨져 있다. 이와 같은 이진 트리의 인오더와 포스트오더가 주어졌을 때, 프리오더를 구하는 프로그램을 작성하시오. 입력첫째 줄에 n(1 ≤ n ≤ 100,000)이 주어진다. 다음 줄에는 인오더를 나타내는 n개의 자연수가 주어지고, 그 다음 줄에는 같은 식으로 포스트오더가 주어진다. 출력첫째 줄에 프리오더를 출력한다. 풀이중위순회의 정보는 노드들간의 좌우관계를 알려준다.후위순회에서의 마지막원소는 항상 루트노드의 값이다.즉, 루트노드를 중위순회..
https://codeforces.com/contest/2063/problem/CCodeforces Round 1000(Div.2) - C. Remove Exactly Two문제 유형: 그리디, 그래프, 정렬, 트리시간 제한: 2초메모리 제한: 256MB 문제You are given a tree∗ of n vertices. You must perform the following operation exactly twice.Select a vertex v; Remove all edges incident to v, and also the vertex v. Please find the maximum number of connected components after performing the operation e..
https://www.acmicpc.net/problem/20040BOJ - 사이클 게임문제 유형: 유니온-파인드, 트리, 서로소-집합문제 난이도: Gold IV시간 제한: 1초메모리 제한: 512MB 문제사이클 게임은 두 명의 플레이어가 차례대로 돌아가며 진행하는 게임으로, 선 플레이어가 홀수 번째 차례를, 후 플레이어가 짝수 번째 차례를 진행한다. 게임 시작 시 0 부터 n − 1 까지 고유한 번호가 부여된 평면 상의 점 n 개가 주어지며, 이 중 어느 세 점도 일직선 위에 놓이지 않는다. 매 차례 마다 플레이어는 두 점을 선택해서 이를 연결하는 선분을 긋는데, 이전에 그린 선분을 다시 그을 수는 없지만 이미 그린 다른 선분과 교차하는 것은 가능하다. 게임을 진행하다가 처음으로 사이클을 완성하는 순간..
https://leetcode.com/problems/find-minimum-diameter-after-merging-two-trees/description/leetcode - Find Minimum Diameter After Merging Two Trees문제 유형: 트리, bfs, 그리디문제 난이도: Hard 문제There exist two undirected trees with n and m nodes, numbered from 0 to n - 1 and from 0 to m - 1, respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges..
https://leetcode.com/problems/minimum-number-of-operations-to-sort-a-binary-tree-by-level/description/leetcode - Minimum Number of Operations to Sort a Binary Tree by Level문제 유형: 정렬, 트리, bfs문제 난이도: Medium 문제You are given the root of a binary tree with unique values.In one operation, you can choose any two nodes at the same level and swap their values.Return the minimum number of operations neede..
https://www.acmicpc.net/problem/15681BOJ - 트리와 쿼리문제 유형: 트리, dfs문제 난이도: Gold V시간 제한: 1초메모리 제한: 128MB 문제간선에 가중치와 방향성이 없는 임의의 루트 있는 트리가 주어졌을 때, 아래의 쿼리에 답해보도록 하자.정점 U를 루트로 하는 서브트리에 속한 정점의 수를 출력한다.만약 이 문제를 해결하는 데에 어려움이 있다면, 하단의 힌트에 첨부한 문서를 참고하자. 입력트리의 정점의 수 N과 루트의 번호 R, 쿼리의 수 Q가 주어진다. (2 ≤ N ≤ 105, 1 ≤ R ≤ N, 1 ≤ Q ≤ 105)이어 N-1줄에 걸쳐, U V의 형태로 트리에 속한 간선의 정보가 주어진다. (1 ≤ U, V ≤ N, U ≠ V)이는 U와 V를 양 끝점으로 ..