#DSU0000048. Một hoặc hai (1 or 2)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Một hoặc hai (1 or 2)
1 or 2
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are face-down cards numbered from to . Each card contains an unknown value equal to either or . You do not know these values, but you are given some relations between them.
There are constraints. Constraint states that is even. It is guaranteed that at least one assignment of satisfies all constraints. At a cost of , you may turn over any card to learn its exact value.
Find the minimum number of cards you must reveal so that the observed values together with the known constraints determine all card values with certainty, regardless of the initially valid assignment.
Input
The first line contains ; each of the next lines contains , with and distinct pairs.
Output
Print one integer, the minimum total cost.
Subtasks
- Subtask 1 (20 points): , ; , ; pairs are distinct; all constraints can be satisfied together.
- Subtask 2 (30 points): , ; , ; pairs are distinct; all constraints can be satisfied together.
- Subtask 3 (50 points): , ; , ; pairs are distinct; all constraints can be satisfied together.
Examples
Input
6 5
1 2 1
2 3 2
1 3 3
4 5 4
5 6 5
Output
2
Explanation
The constraints connect cards in two separate groups: and . Knowing the value of one card in each group determines all remaining values through the given relations. No relation connects the two groups, so one revealed card is insufficient. The answer is 2.