CF466E.Information Graph

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place:

  • either employee y became the boss of employee x (at that, employee x didn't have a boss before);
  • or employee x gets a packet of documents and signs them; then he gives the packet to his boss. The boss signs the documents and gives them to his boss and so on (the last person to sign the documents sends them to the archive);
  • or comes a request of type "determine whether employee x signs certain documents".

Your task is to write a program that will, given the events, answer the queries of the described type. At that, it is guaranteed that throughout the whole working time the company didn't have cyclic dependencies.

公司“X”共有 nn 名员工(为方便起见,我们将其编号为 11 至 nn)。初始时,员工之间没有任何上下级关系。接下来的 mm 天中,每天发生以下三种事件之一:

  • 员工 yy 成为员工 xx 的直属上级(此时员工 xx 此前没有上级);
  • 员工 xx 收到一包文件并签署,然后将该文件包交给自己的上级;上级签署后再交给自己的上级,依此类推(最后一位签署者将文件包送至档案室);
  • 提出一个查询:“判断员工 xx 是否会签署某份特定文件”。

你的任务是编写一个程序,在给定所有事件的前提下,回答上述类型的查询。题目保证在整个工作期间,公司内部的上下级关系始终不构成环(即无循环依赖)。

输入格式

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of employees and the number of events.

Each of the next m lines contains the description of one event (the events are given in the chronological order). The first number of the line determines the type of event t (1 ≤ t ≤ 3).

  • If t = 1, then next follow two integers x and y (1 ≤ x, y ≤ n) — numbers of the company employees. It is guaranteed that employee x doesn't have the boss currently.
  • If t = 2, then next follow integer x (1 ≤ x ≤ n) — the number of the employee who got a document packet.
  • If t = 3, then next follow two integers x and i (1 ≤ x ≤ n; 1 ≤ i ≤ [number of packets that have already been given]) — the employee and the number of the document packet for which you need to find out information. The document packets are numbered started from 1 in the chronological order.

It is guaranteed that the input has at least one query of the third type.

第一行包含两个整数 nn 和 mm(1≤n,m≤1051 \leq n, m \leq 10^5)—— 分别表示员工人数和事件总数。

接下来的 mm 行按时间顺序描述每个事件。每行的第一个数字表示事件类型 tt(1≤t≤31 \leq t \leq 3)。

  • 若 t=1t = 1,则随后给出两个整数 xx 和 yy(1≤x,y≤n1 \leq x, y \leq n)—— 表示公司中两名员工的编号。保证此时员工 xx 尚无直属上司。
  • 若 t=2t = 2,则随后给出一个整数 xx(1≤x≤n1 \leq x \leq n)—— 表示收到文件包的员工编号。
  • 若 t=3t = 3,则随后给出两个整数 xx 和 ii(1≤x≤n1 \leq x \leq n;1≤i≤1 \leq i \leq[目前已发放的文件包总数])—— 表示需查询信息的员工编号及文件包编号。文件包按时间顺序从 11 开始编号。

保证输入中至少存在一个类型为 33 的查询。

输出格式

For each query of the third type print "YES" if the employee signed the document package and "NO" otherwise. Print all the words without the quotes.

对于每个第三种类型的查询,如果员工签署了文件包,则输出“YES”,否则输出“NO”。所有单词均不带引号。

输入输出样例

  • 输入#1

    4 9
    1 4 3
    2 4
    3 3 1
    1 2 3
    2 2
    3 1 2
    1 3 1
    2 2
    3 1 3

    输出#1

    YES
    NO
    YES

输入解题思路,AI测评打分。不知道怎么写?

首页