Information Graph CodeForces - 466E

74HC165级联踩坑实录:STM32读取32路开关状态,时序调试与常见问题排查 本文详细介绍了74HC165级联在STM32读取32路开关状态时的时序调试与常见问题排查。从硬件设计的PCB布局优化、电源噪声控制,到软件时序的精确调校和数据采集策略,提供了完整的解决方案。通过逻辑分析仪和示波器的高效使用,解决了信号延迟和干扰问题,最终实现了稳定可靠的32路信号读取。 阅读详情

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.

Example
Input
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
Output
YES
NO
YES

/*``
题意:好复杂2333嗯。。自己看看吧大概也看得懂。。。2333(其实是我忘记了=-=)
思路:对同一个文件的查询,查询的关系树应该是2操作时的关系树,所以对每个2操作 我们可以把所有的对当时文件的查询一起处理。这里学到了个很厉害的东西。用dfs标记一个点入栈退栈的时间,用一个时间戳Index来计算,那么如果有一对点u,v,v在u到根节点的路径上,即r->v->u;那么必定存在 l[v]<l[u] r[v]>r[u]。由于1操作对关系图中的时间戳不会产生影响,并且需要将对同一文件的查询一起处理,所以我们先把所有操作读入,然后一起操作。2333
对每个1操作,我们用并查集合并x,y,然后先将所有3操作根据文件标号存好,对每个2操作去查询得到当前文件的人和被查询的人是不是同属一个集合,如果属于一个集合说明已经被合并如果同时满足lr的关系那么说明yes 不然no2333
*/

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<map>
using namespace std;

//thanks to pyf ...

#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
typedef pair<int,int> PII;
typedef long long ll;

const int N = 1e5+5;

int fa[N];
vector<int>G[N];//存图
vector<PII>Q[N];//用来存放查询 first是查询的人 second是查询的编号
int l[N],r[N];//入退栈的时间
int ok[N];//yes or no
int vis[N];//用来标记是否有入度,没入度的是根节点
int Index = 0;//时间戳
int doc_id = 0;//文件标号
int n,m;
struct Q
{
    int op;
    int x,y;
}query[N];
void init()//初始化函数
{
    CLR(ok,0);
    CLR(vis,0);
    CLR(l,0);
    CLR(r,0);
    Index = 0;
    doc_id = 0;
    for(int i=0;i<=N;i++)
    {
        fa[i] = i;
        G[i].clear();
        Q[i].clear();
    }

}
int find(int x)
{
    if(fa[x]!=x)
        fa[x] = find(fa[x]);
    return fa[x];
}
void merge(int a,int b)
{
    a = find(a);
    b = find(b);
    if(a!=b)
        fa[a] = fa[b];
}
void get_query()//预处理所有操作
{
    scanf("%d",&m);
    for(int i=0;i<m;i++)
    {
        int op;
        scanf("%d",&query[i].op);
        if(query[i].op==1)
        //反向建图,这样由最高领导指向所有下属,在dfs时对根节点不会重复的去覆盖lr值
        {
            scanf("%d%d",&query[i].x,&query[i].y);
            G[query[i].y].push_back(query[i].x);
            vis[query[i].x] = 1; // 有入度 不是根节点
        }
        else if(query[i].op == 2)
        {
            scanf("%d",&query[i].x);
            query[i].y = ++ doc_id;
        }
        else
        {
            scanf("%d%d",&query[i].x,&query[i].y);
            Q[query[i].y].push_back(mp(query[i].x,i));
            //对同一个文件的查询存放在一起
        }
    }
}
void dfs(int u)//处理 lr
{
    vis[u] = 1;
    l[u] = ++ Index;
    for(int i=0;i<G[u].size();i++)
    {
        int v = G[u][i];
        dfs(v);
    }
    r[u] = ++Index;
}
int main()
{
    while(scanf("%d",&n)==1)
    {
        init();
        get_query();
        for(int i=1;i<=n;i++)
            if(!vis[i])
                dfs(i);
        for(int i=0;i<m;i++)
        {
            if(query[i].op == 1)
            {
                merge(query[i].x,query[i].y);
            }
            else if(query[i].op==2)
            {
                int get_p = query[i].x;
                int doc = query[i].y;
                for(int j=0;j<Q[doc].size();j++)
                //判断是否可行
                {
                    int p = Q[doc][j].first;
                    int id = Q[doc][j].second;
//                  cout << get_p << " " << p << " ";
//                  cout << l[get_p] << " " << l[p] << " " << r[get_p] << " " << r[p] << " " << find(get_p) << " " << find(p) << endl;
                    if(l[get_p]>=l[p]&&r[get_p]<=r[p]&&(find(get_p)==find(p)))
                        ok[id] = 1;
                }
            }
        }
        for(int i=0;i<m;i++)
            if(query[i].op == 3)
                ok[i]==1 ? cout << "YES" << endl : cout << "NO" << endl;
    }
    return 0;
} 
Cadence IC618/Spectre231安装避坑指南:详解License配置、环境变量隔离与依赖检查 本文详细介绍了Cadence IC618/Spectre231的安装与配置避坑指南,包括许可证系统精妙控制、环境隔离模块化实践、依赖管理进阶技巧以及长期维护的黄金法则。通过实战案例和解决方案,帮助工程师构建稳定可靠的EDA工作环境,提升芯片设计效率。 阅读详情

相关推荐

[OpenCV]使用霍夫变换精准检测圆形原理详解与代码实战

dp`是累加器分辨率与图像分辨率的反比,例如`dp=1`时累加器与图像具有相同的分辨率,`dp=2`时累加器分辨率为图像的一半;`HoughCircles`函数的返回值`circles`是一个包含检测到的圆的参数列表,每个圆的格式为`(x, y, r)`,分别代表圆心的x坐标、y坐标和半径。可以使用`cv2.circle()`函数在原图上绘制出检测到的圆,并使用`cv2.imshow()`或`cv2.imwrite()`显示或保存结果图像。霍夫圆变换是霍夫变换的一种扩展,专门用于检测图像中的圆形轮廓。

yr_lu的专栏 510

Codeforces 466E Information Graph(dfs+并查集)

题目链接:Codeforces 466E Information Graph 题目大意:一开始有n个员工,他们互相独立。现在有三种操作。 1 u v,v称为u的上级2 u,从u发起一份文件,逐层递交给上级3 u v,询问u是否查阅过v号文件。 解题思路:将每个文件移动的范围处理出来,然后对于每次询问,将询问拆成两个标记,假设查询x是否浏览过第k号文件,第k号文件的范围为u-v,那

不慌不忙、不急不躁 1483

深入解析AUTOSAR中IIC的MCAL实现与Vector配置实践

本文深入解析AUTOSAR架构中IIC总线的MCAL实现与Vector配置实践,探讨IIC在汽车电子中的特殊定位及Vector的折中方案。通过Channel与Sequence设计模式、Chain特性应用及DaVinci Configurator配置步骤,提供IIC驱动的优化与安全实现方法,助力开发者高效解决车载通信问题。

weixin_29172963的博客 407

Codeforces 466 E. Information Graph

并查集.... E. Information Graph time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output There are n empl

码代码的猿猿 1397

概率论 知识图谱 + 实战案例解析

本文通过构建概率论知识图谱,系统梳理了从随机试验、概率、条件概率到随机变量与分布的核心概念及其内在联系。结合朴素贝叶斯分类器和蒙特卡洛模拟等实战案例,深入解析了条件概率、独立性及大数定律等理论如何应用于机器学习与实际问题求解,旨在帮助读者建立结构化思维,将理论有效转化为解决实际问题的能力。

weixin_29051193的博客 266

Windows下Python调用D435i相机避坑指南:从SDK版本选择到RealSense Viewer报错解决

本文详细介绍了在Windows环境下使用Python调用Intel D435i相机的完整避坑指南。重点解决了SDK版本选择问题,推荐使用稳定的Intel RealSense SDK 2.54.2版本,并提供了从环境配置、常见报错解决到实际应用案例的全流程实践指导,帮助开发者高效完成相机部署与开发。

palm99的专栏 923

Codeforces 466E Information Graph

Information Graph 把询问离线之后就能随便搞了, 去check一下是不是祖先, 可以用倍增也能用dfs序。 #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair&...

120

基于大模型的脑疝全流程预测与诊疗方案研究

目录一、引言1.1 研究背景与目的1.2 研究意义1.3 大模型技术概述二、脑疝概述2.1 定义与分类2.2 发病机制与病因2.3 临床表现2.4 诊断方法三、大模型在脑疝预测中的应用3.1 数据采集与预处理3.2 模型训练与选择3.3 模型验证与优化四、术前预测与评估4.1 病情严重程度预测4.2 手术风险预测4.3 个性化手术方案制定4.4 麻醉方案制定五、术中监测与决策5.1 实时监测指标5.2 大模型辅助决策5.3 应对突发情况六、术后评估与护理6.1 术后恢复情况评估6.2 并发症风险预测与预防6

嵌入式毕设/课设资料清单(速查手册·文档模板·题库,持续更新)→ 见最新文章 1285

【CodeForces】466E Information Graph 离线处理+并查集

传送门:【CodeForces】466E Information Graph

poursoul 1553

tree_sitter多语言解析器配置实战指南

本文是一份详细的Tree-sitter多语言解析器配置实战指南。文章从零开始,手把手指导如何搭建Python环境、安装指定版本的tree-sitter库、下载并编译多种语言的语法规则,最终构建一个统一的解析器库。通过实战代码演示了如何初始化解析器、解析代码并遍历语法树,旨在帮助开发者高效处理多语言代码分析任务,并分享了高级技巧与常见问题排坑经验。

weixin_29245767的博客 267

Burpsuite系列安全渗透--自动扫描生成h5报告

第一章简述 Burpsuite是基于Java的用于web安全的工具,能够进行爬虫、代理、编码、密码爆破等任务,并支持对XSS漏洞、文件包含等漏洞的主动扫描或被动扫描。burpsuite2.0具体分为以下11个模块: Dashboard(仪表盘)——显示任务、实践日志等。 Target(目标)——显示目标目录结构的的一个功能。 Proxy(代理)——拦截HTTP/S的代理服务器,作为一个在浏览器和目标应用程序之间的中间人,允许你拦截,查看,修改在两个方向上的原始数据流。 Intruder(...

魔都虫师的博客 2889

CodeForces 466E. Information Graph (并查集+倍增)

题目: http://codeforces.com/problemset/problem/466/E 题意: 三种操作: 1.y变为x的boss; 2.x签署一份文件并逐级往上传并签署; 3.查询第x个人是否签署第i份文件。 分析: 在线变离线; 用路径压缩的并查集能直接查询当前状态下某个人的最高boss; 签署一份文件时,记录签署此文件最底端的人和最顶端的人; 倍增处理出每个节点往上走1&amp;lt;...

OI -> ACM -> AI 463

基于哈夫曼编码的图像加密算法matlab仿真

哈夫曼编码是一种常用的无损数据压缩算法,其基本思想是根据字符出现的频率构造一棵哈夫曼树,将出现频率高的字符编码为短码,出现频率低的字符编码为长码,从而实现数据的压缩。在图像加密领域,哈夫曼编码也被广泛应用于图像加密算法中,基于哈夫曼编码的图像加密算法具有加密速度快、加密强度高等优点。基于哈夫曼编码的图像加密算法的基本思路是将待加密的图像分为多个小块,对每个小块进行哈夫曼编码,然后将哈夫曼编码后的结果进行异或运算,最后将异或运算后的结果重新编码,以实现图像加密。具体步骤如下:将待加密的图像分成多个小块。

平时工作较为繁忙,私信消息一般晚上回复,谢谢大家~~ 262

Codeforces 466E - Information Graph 【DFS+并查集+预处理】

Codeforces 466E - Information Graph 【DFS+并查集+预处理】 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 foll

Dust_heart的博客 655

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

CodeForces 466E Information Graph --树形转线性+并查集

题意:有三种操作: 1.新增一条边从y连向x,此前x没有父节点 2.x接到一份文件,(文件标号逐次递增),然后将这份文件一路上溯,让所有上溯的节点都接到这份文件 3.查询某个节点x是否接到过文件F 解法: 首先要知道一个性质,节点u在v的上溯路径上的话要满足: L[u]= R[v] (先进后出) 先将所有的边都读入,dfs得出L[u],R[u],然后将查询分为t

c_czl的博客 252

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

codeforces 466E Information Graph 并查集LCA离线一通乱搞

想明白一点就很简单了,询问一个人是否签过一份文件是可以分离出来的,只要一个文件已经被签署了,那么不管什么时候询问,答案都是确定的,所以把3类询问分离出来,每次签完一份文件就处理这份文件相关询问即可//也可能只有我被这种地方卡?#pragma warning(disable:4996) #include #include #include #include #include #include usi

zzblac的专栏 576

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces 466E Information Graph【Dfs处理父子关系+并查集+离线查询】好题!

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

mengxiang000000 507

CF466E Information Graph

一、题目 点此看题

C202044zxy的博客 258

Codeforces854D Jury Meeting

题意:告诉你有n+1个城市,标号0-n,0号是个中心,然后其他n个点每个有一个智障他们都要到0点然后他们n个智障需要在0点至少共同py k天,然后再各自飞回各自原来的城市,飞机要么从0飞到一个城市,要么从一个城市飞到0 题解:我觉得我已经彻底咸鱼了,,,C做了贼久还是队友点了一下才觉得那么简单,,看D的时候已经有点放弃了=-=看题就在瞎看没看到加粗的那句话,感觉血崩。。其实已经想到了相当于两个过程

OneDay_pyf的博客 860

hdu6200mustedge mustedge mustedge

Give an connected undirected graph with n nodes and m edges, (n,m≤105) which has no selfloops or multiple edges initially. Now we have q operations (q≤105):⋅1 u v: add an undirected edge from u to v;

OneDay_pyf的博客 842

Weak Pair HDU - 5877

You are given a rootedrooted tree of NN nodes, labeled from 1 to NN. To the iith node a non-negative value aiai is assigned.An orderedordered pair of nodes (u,v)(u,v) is said to be weakweak if (1)

OneDay_pyf的博客 762

2017年上海金马五校程序设计竞赛(网上资格赛)Problem E : A No-story Kingdom

Description In an unknown island, there is a tree kingdom whose structure is just like a tree. It has a city called root city and as your expectation, this root city has several son cities. And every

OneDay_pyf的博客 668

bzoj1969LANE 航线规划

对Samuel星球的探险已经取得了非常巨大的成就,于是科学家们将目光投向了Samuel星球所在的星系——一个巨大的由千百万星球构成的Samuel星系。 星际空间站的Samuel II巨型计算机经过长期探测,已经锁定了Samuel星系中许多星球的空间坐标,并对这些星球从1开始编号1、2、3……。 一些先遣飞船已经出发,在星球之间开辟探险航线。 探险航线是双向的,例如从1号星球到3号星球开辟探险航线,那

OneDay_pyf的博客 627

570D - Tree Requests

Roman planted a tree consisting of n vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the n - 1 remaining vertices has a parent in the tree. Vertex i

OneDay_pyf的博客 567
上一篇: codeforces-519C
下一篇: Minimum Inversion Number HDU - 1394
OneDay_pyf
博客等级 码龄10年 6粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值