100 atcoder#AGC006F. [AGC006F] Blackout
[AGC006F] Blackout
Score : points
Problem Statement
We have a grid with rows and columns. The cell at the -th row and -th column is denoted (, ).
Initially, of the cells are painted black, and all other cells are white. Specifically, the cells (, ), (, ), , (, ) are painted black.
Snuke will try to paint as many white cells black as possible, according to the following rule:
- If two cells (, ) and (, ) are both black and a cell (, ) is white for integers , paint the cell (, ) black.
Find the number of black cells when no more white cells can be painted black.
Constraints
- All pairs (, ) are distinct.
Input
The input is given from Standard Input in the following format:
Output
Print the number of black cells when no more white cells can be painted black.
3 2
1 2
2 3
3
It is possible to paint one white cell black, as follows:
- Since cells (, ) and (, ) are both black and a cell (, ) is white, paint the cell (, ) black.
2 2
1 1
1 2
4
It is possible to paint two white cells black, as follows:
- Since cells (, ) and (, ) are both black and a cell (, ) is white, paint the cell (, ) black.
- Since cells (, ) and (, ) are both black and a cell (, ) is white, paint the cell (, ) black.
4 3
1 2
1 3
4 4
3
No white cells can be painted black.