Cyclic Components(并查集)

给定一个无向图,任务是找到构成环的连通分量的数量。图由顶点和边组成,边是双向的,不允许自环。连通分量是存在路径连接的所有顶点的集合。一个连通分量是环当且仅当其顶点可以重新排列,使得每个顶点与下一个顶点通过边相连,并且所有边都是不同的。题目提供了一个包含66个连通分量,其中2个是环的例子。解决方案涉及计算每个顶点的度,只有度为2的顶点才可能属于环。通过并查集来检查是否有环,若父节点相同,则环的数量加一。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

链接:http://codeforces.com/contest/977/problem/E
E. Cyclic Components
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an undirected graph consisting of nn vertices and mm edges. Your task is to find the number of connected components which are cycles.

Here are some definitions of graph theory.

An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of vertices. All edges are bidirectional (i.e. if a vertex aa is connected with a vertex bb, a vertex bb is also connected with a vertex aa). An edge can't connect vertex with itself, there is at most one edge between a pair of vertices.

Two vertices uu and vv belong to the same connected component if and only if there is at least one path along edges connecting uu and v

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值