编程介的小学生 2017-04-03 11:11 采纳率: 20.5%
浏览 784
已采纳

Cactus

Cactus is a connected undirected graph in which every edge lies on at most one simple cycle. Intuitively cactus is a generalization of a tree where some cycles are allowed. Your task first is to verify if the given graph is a cactus or not. Important difference between a cactus and a tree is that a cactus can have a number of spanning subgraphs that are also cactuses. The number of such subgraphs (including the graph itself) determines cactusness of a graph (this number is one for a cactus that is just a tree). The cactusness of a graph that is not a cactus is considered to be zero.

The first graph on the picture is a cactus with cactusness 35. The second graph is not a cactus because edge (2, 3) lies on two cycles. The third graph is not a cactus because it is not connected.

Input

The first line of each test case contains two integer numbers n and m (1 ≤ n ≤ 20000, 0 ≤ m ≤ 1000).

Here n is the number of vertices in the graph. Vertices are numbered from 1 to n. Edges of the graphare represented by a set of edge-distinct paths, where m is the number of such paths.

Each of the following m lines contains a path in the graph. A path starts with an integer number ki(2 ≤ ki ≤ 1000) followed by ki integers from 1 to n. These ki integers represent vertices of a path. Path can go to the same vertex multiple times, but every edge is traversed exactly once in the whole input file.

There are no multiedges in the graph (there is at most one edge between any two vertices).

The whole input consists of several test cases. Proceed to the end of file.

Output

For each test case, write to the output file a single integer number - the cactusness of the given graph. Note that cactusness can be quite a large number.

Sample Input

14 3
9 1 2 3 4 5 6 7 8 3
7 2 9 10 11 12 13 10
2 2 14
10 2
7 1 2 3 4 5 6 1
6 3 7 8 9 10 2
5 1
4 1 2 3 4
Sample Output

35
0
0

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-04-16 15:28
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示