Logo
(追記) (追記ここまで)

33398번 - Ald 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 2048 MB111100.000%

문제

You are given a tree. The tree has $n$ vertices, labeled from 1ドル$ to $n$.

Let us denote the path between vertices $a$ and $b$ as $(a, b)$. Let the $d$-set of a path be the set of vertices on the tree located within a distance $\le d$ from at least one vertex of the path. For example, the 0ドル$-set of a path is the set of its vertices. The distance between vertices is the number of edges on the path between these vertices.

Let $S$ be a multiset of tree paths. Initially, $S$ is empty. Your task is to process the following queries:

  • "1 $u$ $v$": add path $(u, v)$ into $S$ (1ドル \le u, v \le n$).
  • "2 $u$ $v$": delete a single path $(u, v)$ from $S$ (1ドル \le u, v \le n$). Note that $(u, v)$ and $(v, u)$ denote the same path. For example, if $S=\{(2, 3), (2, 3)\},ドル then after a query "2 3 2", we will have $S=\{(2, 3)\}$. Before this query, it is guaranteed that at least one path $(u, v)$ or $(v, u)$ is present in $S$.
  • "3 $d$": print the size of intersection of $d$-sets of all paths from $S$ (0ドル \le d \le n$). If $S$ is empty, print 0ドル$.

입력

The first line contains an integer $t,ドル the number of test cases (1ドル \le t \le 10^4$). The test cases follow.

The first line of each test case contains two integers $n$ and $q$ (1ドル \le n, q \le 10^5$), the number of vertices in the tree and the number of queries.

Each of the following $n - 1$ lines contains two integers $u_i$ and $v_i$: indices of vertices connected by the $i$-th edge of the tree (1ドル \le u_i, v_i \le n$).

The following $q$ lines contain queries in the format described in the statement.

The sum of $n$ over all test cases does not exceed 10ドル^5$. The sum of $q$ over all test cases does not exceed 10ドル^5$.

출력

For each query of the third type, output a single line with the answer.

제한

예제 입력 1

1
8 7
1 2
1 3
3 4
2 5
4 6
1 7
6 8
3 1
1 7 8
3 1
2 7 8
1 8 6
1 7 7
3 3

예제 출력 1

0
7
3

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2023 > Day 7: Peking U Contest G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /