Under construction

Still being built. Things may change

Cactusophobia

Time limit2sMemory limit512 MB

Summary
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.
Level

Medium7 of 10

Topics
Graph, DFS
Solved
No attempts yet

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 nn and mm (2≤n≤100002 \le n \le 10000), the number of vertices and edges. Each of the next mm lines contains three integers uu, vv, and cc (1≤u,v≤n1 \le u, v \le n, u≠vu \ne v, 1≤c≤m1 \le c \le m), 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.

Examples2

  1. Example 1

    Input
    4 4
    1 2 4
    2 3 1
    3 4 2
    4 2 3
    
    Expected output
    3
    
  2. Example 2

    Input
    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
    
    Expected output
    6