CF1843F1.Omsk Metro (simple version)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the simple version of the problem. The only difference between the simple and hard versions is that in this version u=1u = 1 .

As is known, Omsk is the capital of Berland. Like any capital, Omsk has a well-developed metro system. The Omsk metro consists of a certain number of stations connected by tunnels, and between any two stations there is exactly one path that passes through each of the tunnels no more than once. In other words, the metro is a tree.

To develop the metro and attract residents, the following system is used in Omsk. Each station has its own weight x{1,1}x \in \{-1, 1\} . If the station has a weight of 1-1 , then when the station is visited by an Omsk resident, a fee of 11 burle is charged. If the weight of the station is 11 , then the Omsk resident is rewarded with 11 burle.

Omsk Metro currently has only one station with number 11 and weight x=1x = 1 . Every day, one of the following events occurs:

  • A new station with weight xx is added to the station with number viv_i , and it is assigned a number that is one greater than the number of existing stations.
  • Alex, who lives in Omsk, wonders: is there a subsegment \dagger (possibly empty) of the path between vertices uu and vv such that, by traveling along it, exactly kk burles can be earned (if k<0k < 0 , this means that kk burles will have to be spent on travel). In other words, Alex is interested in whether there is such a subsegment of the path that the sum of the weights of the vertices in it is equal to kk . Note that the subsegment can be empty, and then the sum is equal to 00 .

You are a friend of Alex, so your task is to answer Alex's questions.

\dagger Subsegment — continuous sequence of elements.

输入格式

The first line contains a single number tt ( 1t1041 \leq t \leq 10^4 ) — the number of test cases.

The first line of each test case contains the number nn ( 1n21051 \leq n \leq 2 \cdot 10^5 ) — the number of events.

Then there are nn lines describing the events. In the ii -th line, one of the following options is possible:

  • First comes the symbol "+" (without quotes), then two numbers viv_i and xix_i ( xi{1,1}x_i \in \{-1, 1\} , it is also guaranteed that the vertex with number viv_i exists). In this case, a new station with weight xix_i is added to the station with number viv_i .
  • First comes the symbol "?" (without quotes), and then three numbers uiu_i , viv_i , and kik_i ( nkin-n \le k_i \le n ). It is guaranteed that the vertices with numbers uiu_i and viv_i exist. In this case, it is necessary to determine whether there is a subsegment (possibly empty) of the path between stations uiu_i and viv_i with a sum of weights exactly equal to kik_i . In this version of the task, it is guaranteed that ui=1u_i = 1 .

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each of Alex's questions, output "Yes" (without quotes) if the subsegment described in the condition exists, otherwise output "No" (without quotes).

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

输入输出样例

  • 输入#1

    1
    8
    + 1 -1
    ? 1 1 2
    ? 1 2 1
    + 1 1
    ? 1 3 -1
    ? 1 1 1
    ? 1 3 2
    ? 1 1 0

    输出#1

    NO
    YES
    NO
    YES
    YES
    YES
  • 输入#2

    1
    10
    + 1 -1
    + 1 -1
    + 3 1
    + 3 -1
    + 3 1
    ? 1 6 -1
    ? 1 6 2
    ? 1 2 0
    ? 1 5 -2
    ? 1 4 3

    输出#2

    YES
    NO
    YES
    YES
    NO

说明/提示

Explanation of the first sample.

The answer to the second question is "Yes", because there is a path 11 .

In the fourth question, we can choose the 11 path again.

In the fifth query, the answer is "Yes", since there is a path 131-3 .

In the sixth query, we can choose an empty path because the sum of the weights on it is 00 .

It is not difficult to show that there are no paths satisfying the first and third queries.

首页