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.
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.
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.
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
YES NO YES
题意:
给出 N 个结点和 M 个事件,1 代表 x 是 y 的 boss,2 代表从 x 开始往上传文件,3 代表询问第 x 个人有没有收到过这个文件。每次往上传文件都是传到最高的 boss 为止。输出每次询问的结果,有则输出 YES, 没有则输出 NO。
思路:
并查集。维护两个并查集,一个是更新的,一个是不更新的,并且记录每次文件从哪里开始到哪里结束。最后询问的时候,查找不更新的并查集即可。
AC:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int NMAX = 100005; int root[NMAX], num[NMAX]; int f[NMAX], tt[NMAX]; int Find (int x) { return x == root[x] ? x : root[x] = Find(root[x]); } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { root[i] = num[i] = i; } int ans = 0; while (m--) { int t; scanf("%d", &t); if (t == 1) { int x, y; scanf("%d%d", &x, &y); num[x] = root[x] = y; } else if (t == 2) { int x; scanf("%d", &x); ++ans; f[ans] = x; tt[ans] = Find(x); } else if (t == 3) { int x, i; scanf("%d%d", &x, &i); bool temp = false; int k = f[i]; if (k == x || x == tt[i]) temp = true; while (!temp && k != tt[i]) { if (k == x) { temp = true; break; } else k = num[k]; } if (temp) printf("YES\n"); else printf("NO\n"); } } return 0; }
相关推荐
网络(图 graph)数据集CollegeMsg网络(图 graph)数据集CollegeMsg网络(图 graph)数据集CollegeMsg网络(图 graph)数据集CollegeMsg网络(图 graph)数据集CollegeMsg网络(图 graph)数据集CollegeMsg网络(图...
Graphis,这个名称可能对许多人来说并不陌生,它代表着一个专注于平面设计、字体设计和摄影的权威平台。本文将围绕Graphis这一主题,深入探讨字体设计的艺术与技术,旨在揭示其背后的创作理念与实用技巧。 首先,让...
西门子 GRAPH 帮助手册 西门子 GRAPH 帮助手册是有关西门子 GRAPH 编程语言的详细指导手册,旨在帮助用户快速掌握 GRAPH 编程语言的基本知识和应用。 GRAPH 编程语言是一种图形化的编程语言,用于创建顺序控制系统...
5. **Hbase配置**:Janusgraph可以使用Hbase作为持久化存储,需要在Hbase中创建Janusgraph所需的表,并配置相应的Janusgraph-Hbase连接参数。 6. **Elasticsearch配置**:Elasticsearch作为Janusgraph的索引存储,...
《S7-Graph汉化详解》 在工业自动化领域,西门子的S7-Graph是一款广泛应用的编程工具,主要用于创建和编辑S7系列PLC(可编程逻辑控制器)的顺序控制程序。S7-Graph以其图形化界面和强大的功能,使得复杂的顺序逻辑...
MFC源代码 GRAPH.13MFC源代码 GRAPH.13MFC源代码 GRAPH.13MFC源代码 GRAPH.13MFC源代码 GRAPH.13MFC源代码 GRAPH.13MFC源代码 GRAPH.13MFC源代码 GRAPH.13MFC源代码 GRAPH.13MFC源代码 GRAPH.13MFC源代码 GRAPH.13...
the dynamic information as the graph evolving. In particular, the proposed framework can keep updating node information by capturing the sequential information of edges (interactions), the time ...
Graph
本文档详细介绍了 S7-1500 GRAPH 指令的使用方法,包括 GRAPH 顺控器、GRAPH 操作、GRAPH LAD 指令、GRAPH FBD 指令等内容。 GRAPH 顺控器是 S7-1500 程序设计中的一个重要组件,它可以用于控制程序的执行顺序。 ...
在GraphSLAM中,随着机器人移动并收集新的观测数据,图会不断扩展。每次新增一个观测时,都会添加一个新的节点和边。节点代表当前的位姿估计,边则表示新观测与已有信息之间的关系。例如,激光雷达或视觉传感器的...
在PowerBuilder(PB)开发环境中,`pb graph显示数值`是一个关键功能,它涉及到如何在图形图表(graph)上清晰地展示数据值。这通常是为了提高数据可视化的可读性和理解性。`graph类型数据窗口改变graph类型`指的是...
在Unity引擎中,Shader Graph是一种强大...在实际项目中,开发者可以通过导入这些Shader Graph,并在Unity编辑器中调整参数,以适应各种游戏美术需求。同时,这些实例也为学习Shader Graph的使用提供了宝贵的参考资料。
However, these tasks require dealing with non-Euclidean graph data that contains rich relational information between elements and cannot be well handled by traditional deep learning models (e.g., ...
It converts the graph data into a low dimensional space in which the graph structural information and graph properties are maximumly preserved. In this survey, we conduct a comprehensive review of ...
janusgraph可视化 janusgraph可视化的简单工具。 (一个简单的janusgraph查询可视化工具) 使用工具查看janusgraph。 怎么跑? 下载发布jar文件 nohup java -jar janusgraph-visualization-x.x.x.jar >/dev/null ...
GraphDB Linux 安装包
1. **创建GRAPH控件并设置属性**:使用`GRAPH_CreateEx()`函数创建控件,并指定初始位置、大小、父窗口等信息。 2. **创建数据对象**:使用`GRAPH_DATA_YT_Create()`或`GRAPH_DATA_XY_Create()`函数创建数据对象。...
2. **顶点和边的表示**:GraphX中的顶点和边都是通过RDD(弹性分布式数据集)来表示的,这些RDD包含了图中所有顶点或边的信息。每个顶点都有一个唯一的ID,称为`VertexId`。 3. **分区策略**:GraphX采用哈希函数对...
在安装JanusGraph时,你需要首先选择合适的后端存储系统,并配置相应的连接参数。安装过程中可能需要安装依赖库,例如Apache Hadoop、Zookeeper等。安装完成后,你可以通过TinkerPop的Gremlin语句来操作JanusGraph,...
安装过程中,需确保计算机满足软件的硬件需求,并遵循官方提供的安装指南。同时,对于注册机的使用,虽然可以绕过正版验证,但应理解这是不合法的行为,可能会导致法律问题和软件不稳定的风险。 总的来说,S7-Graph...