博客
关于我
ACM-ICPC寒假算法训练2:高级数据结构1:并查集2(带权并查集)
阅读量:321 次
发布时间:2019-03-04

本文共 417 字,大约阅读时间需要 1 分钟。

今天练习带权并查集,涉及两个题目,分别处理不同状态的合并关系。题一处理二状态关系,题二处理三状态关系,理解状态关系并正确更新权值是关键。

题一分析:

  • a和b在同一棵树上时,根据dis值判断帮派。
  • 使用find和merge函数进行查找和合并,更新dis值。
  • AC代码通过find和merge函数处理查询,返回相应状态。

题二分析:

  • 处理三种状态关系:0(同类)、1(x吃y)、2(x被y吃)。
  • 初始化时每个节点自己与自己同类。
  • find函数更新dis值,模3运算。
  • merge函数根据cmd更新dis值,合并时根据cmd判断x和y的关系。
  • AC代码处理多查询,初始化节点,根据cmd判断状态或合并,返回结果。

练习总结:

  • 带权并查集适用于处理多种状态关系,需正确计算权值。
  • 理解状态关系和合并逻辑,确保权值更新正确。
  • 测试不同情况,确保代码正确性和效率。

通过这两个题目,对带权并查集有了更深入的理解,未来遇到类似问题时可以更从容应对。

转载地址:http://gnmq.baihongyu.com/

你可能感兴趣的文章
Symbolic Aggregate approXimation(SAX,符号聚合近似)介绍-ChatGPT4o作答
查看>>
Orcale表被锁
查看>>
svn访问报错500
查看>>
Orderer节点启动报错解决方案:Not bootstrapping because of 3 existing channels
查看>>
org.apache.ibatis.exceptions.PersistenceException:
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
SQL-CLR 类型映射 (LINQ to SQL)
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
查看>>
org.tinygroup.serviceprocessor-服务处理器
查看>>
org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
查看>>
org/hibernate/validator/internal/engine
查看>>
Orleans框架------基于Actor模型生成分布式Id
查看>>