#t525. 团伙

团伙

The Gang

Problem Background

Special for beginners, ^_^

Problem Description

In a certain city there live nn people. Any two acquaintances are either friends or enemies, and they satisfy:

  1. A friend of my friend is my friend;
  2. An enemy of my enemy is my friend.

All people who are friends form a gang. Given mm pieces of information about these nn people — that two particular people are friends, or that two particular people are enemies — please write a program to compute the maximum possible number of gangs in this city.

Input Format

The first line contains nn and mm, with 1<n<10001 < n < 1000, 1≤m≤1051 \le m \le 10^5.

The following mm lines each contain p x yp\ x\ y. pp is 00 or 11. When p=0p = 0, it means xx and yy are friends; when p=1p = 1, it means xx and yy are enemies.

Output Format

One integer: the maximum possible number of gangs among these nn people.

Sample Input

6 4
1 1 4
0 3 5
0 4 6
1 1 2

Sample Output

3

Constraints

Time limit: 1s; memory limit: 1024 KiB for each test case.