Cactusophobia
Time limit2sMemory limit512 MB
Given an edge cactus with colored edges, remove the fewest edges to make it a tree while keeping as many distinct colors as possible, then print that maximum count.
Statement
A tree is a connected undirected graph with no cycles. An edge cactus is a connected undirected graph without loops or parallel edges, such that each edge belongs to at most one cycle.
Vasya has an edge cactus, and each edge has a color.
Vasya wants to remove the minimum number of edges so that the cactus becomes a tree. Among all ways to do this, he wants the resulting tree to have as many different edge colors as possible. Find the maximum number of different colors the resulting tree can have.
Input
The first line contains two integers and (), the number of vertices and edges. Each of the next lines contains three integers , , and (, , ), the endpoints of an edge and its color. The graph is guaranteed to be an edge cactus.
Output
Print one integer, the maximum number of different colors the resulting tree can have.