- 0
- 0
- 约3.04千字
- 约 4页
- 2025-10-22 发布于北京
- 举报
ProblemH
HappyPainting!
Thereisaforestofcolorfulrootedtreescontainingnnodes.Youaregivenm
operations.Executethemonebyone,andoutputtheresults.
1xyc
Changexsfathertoy.Ifx=yorxisaancestorofy,simplyignoreit.Theedge
weenxanditsoldfatherisremoved,andthenewedgeshouldbepaintedwith
colorc.
2xyc
Paintalltheedgesalongthepathx-ywithcolorc.Ifthereisnopathweenx
andy,simplyignoreit.
3xy
Countthenumberofedgesalongthepathx-y,andthetotalnumberofcolorsamong
theseedges.
Input
Theinputcontainsseveraltestcases.Thefirstlineofeachtestcasecontains
twointegersnandm(1=n=50,000,1=m=200,000).Nodesarenumberedfrom1to
n.ThesecondlinecontainsnintegersF[i](0=F[i]=n),thefatherofeachnode
(F[i]=0meansthenodeistherootofatree).Thenextlinecontainsnintegers
C[i](1=C[i]=30),thecolorsoftheedgesweeneachnodeanditsfather(for
rootnodes,thecorrespondingcolorshouldbeignored).Eachofthenextmlines
containsanoperation.Foralloperations,1=x,y=n,foreachtype-2operation,
1=c=30.Theinputisterminatedbyend-of-file(EOF).Thesizeofinputfile
doesnotexceed5MB.
Output
Foreachtype-3operation,outputtwointegers:thenumberofedgesandthenumber
ofcolorsamongtheseedges.
SampleInput
66
346
问题H
绘画快乐!
有一个由彩色根树组成的森林,其中包含n个节点。给你m次操作。一一执行,并输出结果。
1xyc
将x的父亲改为y。如果x=y或x是y的祖先,则忽略它。x和它的旧父亲之间的边被删除,
新的边应该涂上颜色c。
2xy坐标
用颜色c沿路径x‑y绘制所有边。如果x和y之间没有路径,则忽略它。
3xy
计算沿路径x‑y的边数,以及这些边中的颜色总数。
输入
您可能关注的文档
最近下载
- 国企面试问题及答案-国企面试题目和解答-国企单位面试的题目.docx VIP
- 沈阳工业大学《数据库原理》2025 学年第二学期期末试卷.pdf VIP
- 储能变流器简介及英飞凌IGBT解决方案-TTA2019.pdf VIP
- 房产过户合同8篇.docx VIP
- 大学生心理健康教育 课件全套 总共13章 大学生心理健康与心理咨询 ,心理危机与生命教育等课件.pptx VIP
- 茅台国企面试题目及答案.doc VIP
- X-MINI 杂物梯主板说明书.pdf VIP
- 市政协副主席2025年度民主生活会对照检查材料(五个带头).docx VIP
- 2023年沈阳工业大学计算机科学与技术专业《计算机网络》科目期末试卷B(有答案).docx VIP
- 花式年糕加工机设计【开题报告+文献综述+毕业设计】.Doc VIP
原创力文档

文档评论(0)