#P1892. [BalticOI 2003] 团伙

[BalticOI 2003] 团伙

Description

There are nn people, and between any two people there are two kinds of relations: friend and enemy. We know:

  • A person's friend's friend is also a friend.
  • A person's enemy's enemy is a friend.

We want to form groups. Two people are in the same group if and only if they are friends. Find the maximum possible number of groups among these people.

Input Format

The first line contains an integer nn, the number of people.

The second line contains an integer mm, meaning that mm relations follow.

Each of the next mm lines contains a character optopt and two integers p,qp, q, representing the type of relation (friend or enemy), the first person, and the second person among the two who have a relation. The character optopt has two possibilities:

  • If optopt is F, then pp and qq are friends.
  • If optopt is E, then pp and qq are enemies.

Output Format

Output a single integer on one line: the maximum number of groups.

6
4
E 1 4
F 3 5
F 4 6
E 1 2
3

Hint

For 100%100\% of the testdata, 2n10002 \le n \le 1000, 1m50001 \le m \le 5000, 1p,qn1 \le p, q \le n.

Translated by ChatGPT 5