A9617 | Information Graph
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
- 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.
输入格式
The first line contains two integers $n$ and $m$ ( $1<=n,m<=10^{5}$ ) — 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.
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.
输出格式
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.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted