搜索
首页web前端html教程CF 题目集锦 PART 5 #266 div 2 E_html/css_WEB-ITnose

【原题】

E. Information Graph

time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

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.

    Input

    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.

    Output

    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.

    Sample test(s)

    input

    4 91 4 32 43 3 11 2 32 23 1 21 3 12 23 1 3

    output

    YESNOYES

    【题意】意思看了半天~就是有N个人,M个操作。每次操作有3种。

    ①把x的父亲置为y。

    ②从x开始发新的一份文件(是从1开始标号的)。从x开始,一直传递到最远的祖先。

    ③询问x号文件有没有落到y的手里。

    【分析】即要简单地判断y是否是x的祖先。一开始有思维定势,觉得要求一遍LCA。但是后来想了想,可以直接用DFS序搞出同一棵树的深度,再用并查集维护是否在同一棵树上。代码很简单。

    【代码】

    #include<cstdio>#include<vector>#define N 200005#define pb push_backusing namespace std;vector<int>son[N],ask[N];struct arr{int x,y,id,opt;}a[N];int f[N],L[N],R[N],fa[N],ans[N];int i,n,m,now,num,id,tot,P,j;inline int get(int u){return f[u]==u?f[u]:f[u]=get(f[u]);}void dfs(int k){  L[k]=++tot;  for (int i=0;i<son dfs r main scanf for if son ask f id="ask[now][j];num=a[id].x;">=R[a[i].x]) ans[id]=1;    }  }}</son></int></vector></cstdio>

    声明
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
    cf罗技一键宏怎么设置?cf罗技鼠标宏设置cf罗技一键宏怎么设置?cf罗技鼠标宏设置Mar 14, 2024 pm 10:50 PM

      鼠标宏为鼠标键赋予一系列复杂的操作,可以简单地理解为鼠标的快捷键设置,点击设置鼠标宏的按键后,就能完成一些平时无法做到的操作。那么玩cf要如何设置鼠标宏呢?下面就来看看cf罗技鼠标宏设置教程吧。  1、首先是在计算机安装Logitech游戏软件,然后点击如图中箭头所示,打开自定义按钮的设置界面。接着,您需要选择一个键,比如左键,点击小箭头,然后在弹出的菜单中选择“编辑命令”,这样就可以打开左键宏的设置界面。  3、接着就是点击按钮,如图中红箭头所示,点击文本框随便输入一个按键,注意的是比如A

    css怎么实现div缺一个角css怎么实现div缺一个角Jan 30, 2023 am 09:23 AM

    css实现div缺一个角的方法:1、创建一个HTML示例文件,并定义一个div;2、给div设置宽高背景色;3、给需要删除一角的div增加一个伪类,将伪类设置成跟背景色一样的颜色,然后旋转45度,再定位到需要去除的那个角即可。

    基于 ChatGPT API 的划词翻译浏览器脚本实现基于 ChatGPT API 的划词翻译浏览器脚本实现May 01, 2023 pm 03:28 PM

    前言最近GitHub上有个基于ChatGPTAPI的浏览器脚本,openai-translator,短时间内star冲到了12k,功能上除了支持翻译外,还支持润色和总结功能,除了浏览器插件外,还使用了tauri打包了一个桌面客户端,那抛开tauri是使用rust部分,那浏览器部分实现还是比较简单的,今天我们就来手动实现一下。openAI提供的接口比如我们可以复制以下代码,在浏览器控制台中发起请求,就可以完成翻译//示例constOPENAI_API_KEY="s

    div与span的区别有哪些div与span的区别有哪些Nov 02, 2023 pm 02:29 PM

    区别有:1、div是一个块级元素,span是一个行内元素;2、div会自动占据一行,span则不会自动换行;3、div用于包裹比较大的结构和布局,span用于包裹文本或者其他行内元素;4、div可以包含其他块级元素和行内元素,span可以包含其他行内元素。

    div盒模型是什么div盒模型是什么Oct 09, 2023 pm 05:15 PM

    div盒模型是一种用于网页布局的模型,它将网页中的元素视为一个个矩形的盒子,这个模型包含了四个部分:内容区域、内边距、边框和外边距。div盒模型的好处是可以方便地控制网页布局和元素之间的间距,通过调整内容区域、内边距、边框和外边距的大小,可以实现各种不同的布局效果,盒模型也提供了一些属性和方法,可以通过CSS和JavaScript来动态地改变盒子的样式和行为。

    iframe和div有什么不同iframe和div有什么不同Aug 28, 2023 am 11:46 AM

    iframe和div的不同是iframe主要用于引入外部内容,可以加载其他网站的内容或将一个网页分割成多个区域,每个区域有自己的独立的浏览上下文,而div主要用于分割和组织内容的区块,用于布局和样式控制。

    WIN10系统cf怎么调烟雾头WIN10系统cf怎么调烟雾头Feb 26, 2024 pm 04:17 PM

    调整步骤:1、在Win10系统桌面,右键点击开始按钮,选择“设置”;2、点击“系统”图标;3、点击左侧边栏的“显示”菜单项;4、在右侧点击“显示适配器属性”快捷链接;5、点击“列出所有模式”按钮;6、从所有模式中选择“1024*768真彩色 60赫兹”一项;7、点击上面的“监视器”标签,将其设置为60赫兹;8、点击“确定”,然后重启计算机即可。

    如何将两个div并排显示如何将两个div并排显示Nov 01, 2023 am 11:36 AM

    方法有:1、将两个div元素设置为“float:left;”属性;2、使用CSS的flex布局可以轻松实现元素的并排显示;3、使用CSS的grid布局也可以实现元素的并排显示。

    See all articles

    热AI工具

    Undresser.AI Undress

    Undresser.AI Undress

    人工智能驱动的应用程序,用于创建逼真的裸体照片

    AI Clothes Remover

    AI Clothes Remover

    用于从照片中去除衣服的在线人工智能工具。

    Undress AI Tool

    Undress AI Tool

    免费脱衣服图片

    Clothoff.io

    Clothoff.io

    AI脱衣机

    AI Hentai Generator

    AI Hentai Generator

    免费生成ai无尽的。

    热门文章

    R.E.P.O.能量晶体解释及其做什么(黄色晶体)
    2 周前By尊渡假赌尊渡假赌尊渡假赌
    仓库:如何复兴队友
    4 周前By尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island冒险:如何获得巨型种子
    4 周前By尊渡假赌尊渡假赌尊渡假赌

    热工具

    SublimeText3 Mac版

    SublimeText3 Mac版

    神级代码编辑软件(SublimeText3)

    DVWA

    DVWA

    Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

    SecLists

    SecLists

    SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

    Atom编辑器mac版下载

    Atom编辑器mac版下载

    最流行的的开源编辑器

    ZendStudio 13.5.1 Mac

    ZendStudio 13.5.1 Mac

    功能强大的PHP集成开发环境