ADACHERY – Ada and Cherry Solution

SPOJ Solution

As you might already know, Ada the Ladybug is a farmer. She grows cherry and now she wants to collect them. She is wondering about the number of cherries she will collect. But befor you could help here, you shall know some biological facts:

Firstly, almost everyone think that cherry-tree is a tree. But it might not be true – in fact, it is a graph.

Secondly, you have to know, how a cherry looks like. It is not hard to recognize a chery – it is a node, which is connected to another two nodes, which are NOT connected.

NOTE: Even though the cherry-tree structure might be weird, note that there won’t be any multi-branches nor self-branches. Anyway do not assume it is not a cherry-forest.


The first line contains two integers 1 ≤ N, M ≤ 105, the number of nodes of cherry-tree and the number of branches (edges) connecting them.

The next M lines contains two integers 0 ≤ a, b < N, the branch connecting two nodes.


Print a single line – the number of cherries on the cherry-tree.


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.