303726: CF720B. Cactusophobia

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Cactusophobia

题意翻译

**题目描述** 树是一个没有循环的连通无向图。 仙人掌图是一个无环、无平行边的连通无向图,每个边最多只属于一个环。Vasya 有一个仙人掌图,图的每一个边都有颜色。 Vasya 想移除最少数量的边,这样他的仙人掌图就变成了一棵树。 Vasya移除后,树上有尽可能多的不同颜色的边。请帮助他找出树上可以有多少种不同的颜色。 简单来说,就是让你求把这棵仙人掌删边成一棵 n 个节点的树后剩余的颜色最多种类数。 **输入格式** 第一行输入两个整数 n, m 分别代表顶点数和边数。 n<=10000 下面 m 行包含三个整数 u, v, c 表示一条从 u 连向 v 颜色为 c 的边。输入数据保证是一个仙人掌图。 **输出格式** 输出最多颜色数。

题目描述

Tree is a connected undirected graph that has no cycles. Edge cactus is a connected undirected graph without loops and parallel edges, such that each edge belongs to at most one cycle. Vasya has an edge cactus, each edge of this graph has some color. Vasya would like to remove the minimal number of edges in such way that his cactus turned to a tree. Vasya wants to make it in such a way that there were edges of as many different colors in the resulting tree, as possible. Help him to find how many different colors can the resulting tree have.

输入输出格式

输入格式


The first line contains two integers: $ n $ , $ m $ ( $ 2<=n<=10000 $ ) — the number of vertices and the number of edges in Vasya's graph, respectively. The following $ m $ lines contain three integers each: $ u $ , $ v $ , $ c $ ( $ 1<=u,v<=n $ , $ u≠v $ , $ 1<=c<=m $ ) — the numbers of vertices connected by the corresponding edge, and its color. It is guaranteed that the described graph is indeed an edge cactus.

输出格式


Output one integer: the maximal number of different colors that the resulting tree can have.

输入输出样例

输入样例 #1

4 4
1 2 4
2 3 1
3 4 2
4 2 3

输出样例 #1

3

输入样例 #2

7 9
1 2 1
2 3 4
3 1 5
1 4 5
4 5 2
5 1 6
1 6 4
6 7 6
7 1 3

输出样例 #2

6

Input

题意翻译

**题目描述** 树是一个没有循环的连通无向图。 仙人掌图是一个无环、无平行边的连通无向图,每个边最多只属于一个环。Vasya 有一个仙人掌图,图的每一个边都有颜色。 Vasya 想移除最少数量的边,这样他的仙人掌图就变成了一棵树。 Vasya移除后,树上有尽可能多的不同颜色的边。请帮助他找出树上可以有多少种不同的颜色。 简单来说,就是让你求把这棵仙人掌删边成一棵 n 个节点的树后剩余的颜色最多种类数。 **输入格式** 第一行输入两个整数 n, m 分别代表顶点数和边数。 n<=10000 下面 m 行包含三个整数 u, v, c 表示一条从 u 连向 v 颜色为 c 的边。输入数据保证是一个仙人掌图。 **输出格式** 输出最多颜色数。

加入题单

上一题 下一题 算法标签: