搜索
首页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
    HTML:结构,CSS:样式,JavaScript:行为HTML:结构,CSS:样式,JavaScript:行为Apr 18, 2025 am 12:09 AM

    HTML、CSS和JavaScript在Web开发中的作用分别是:1.HTML定义网页结构,2.CSS控制网页样式,3.JavaScript添加动态行为。它们共同构建了现代网站的框架、美观和交互性。

    HTML的未来:网络设计的发展和趋势HTML的未来:网络设计的发展和趋势Apr 17, 2025 am 12:12 AM

    HTML的未来充满了无限可能。1)新功能和标准将包括更多的语义化标签和WebComponents的普及。2)网页设计趋势将继续向响应式和无障碍设计发展。3)性能优化将通过响应式图片加载和延迟加载技术提升用户体验。

    HTML与CSS vs. JavaScript:比较概述HTML与CSS vs. JavaScript:比较概述Apr 16, 2025 am 12:04 AM

    HTML、CSS和JavaScript在网页开发中的角色分别是:HTML负责内容结构,CSS负责样式,JavaScript负责动态行为。1.HTML通过标签定义网页结构和内容,确保语义化。2.CSS通过选择器和属性控制网页样式,使其美观易读。3.JavaScript通过脚本控制网页行为,实现动态和交互功能。

    HTML:是编程语言还是其他?HTML:是编程语言还是其他?Apr 15, 2025 am 12:13 AM

    HTMLISNOTAPROGRAMMENGUAGE; ITISAMARKUMARKUPLAGUAGE.1)htmlStructures andFormatSwebContentusingtags.2)itworkswithcsssforstylingandjavascript for Interactivity,增强WebevebDevelopment。

    HTML:建立网页的结构HTML:建立网页的结构Apr 14, 2025 am 12:14 AM

    HTML是构建网页结构的基石。1.HTML定义内容结构和语义,使用、、等标签。2.提供语义化标记,如、、等,提升SEO效果。3.通过标签实现用户交互,需注意表单验证。4.使用、等高级元素结合JavaScript实现动态效果。5.常见错误包括标签未闭合和属性值未加引号,需使用验证工具。6.优化策略包括减少HTTP请求、压缩HTML、使用语义化标签等。

    从文本到网站:HTML的力量从文本到网站:HTML的力量Apr 13, 2025 am 12:07 AM

    HTML是一种用于构建网页的语言,通过标签和属性定义网页结构和内容。1)HTML通过标签组织文档结构,如、。2)浏览器解析HTML构建DOM并渲染网页。3)HTML5的新特性如、、增强了多媒体功能。4)常见错误包括标签未闭合和属性值未加引号。5)优化建议包括使用语义化标签和减少文件大小。

    了解HTML,CSS和JavaScript:初学者指南了解HTML,CSS和JavaScript:初学者指南Apr 12, 2025 am 12:02 AM

    WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

    HTML的角色:构建Web内容HTML的角色:构建Web内容Apr 11, 2025 am 12:12 AM

    HTML的作用是通过标签和属性定义网页的结构和内容。1.HTML通过到、等标签组织内容,使其易于阅读和理解。2.使用语义化标签如、等增强可访问性和SEO。3.优化HTML代码可以提高网页加载速度和用户体验。

    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.能量晶体解释及其做什么(黄色晶体)
    1 个月前By尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O.最佳图形设置
    1 个月前By尊渡假赌尊渡假赌尊渡假赌
    威尔R.E.P.O.有交叉游戏吗?
    1 个月前By尊渡假赌尊渡假赌尊渡假赌

    热工具

    SublimeText3 Linux新版

    SublimeText3 Linux新版

    SublimeText3 Linux最新版

    EditPlus 中文破解版

    EditPlus 中文破解版

    体积小,语法高亮,不支持代码提示功能

    PhpStorm Mac 版本

    PhpStorm Mac 版本

    最新(2018.2.1 )专业的PHP集成开发工具

    MinGW - 适用于 Windows 的极简 GNU

    MinGW - 适用于 Windows 的极简 GNU

    这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

    ZendStudio 13.5.1 Mac

    ZendStudio 13.5.1 Mac

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