C. Peaceful Rooks

C. Peaceful Rooks

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a n×nn×n chessboard. Rows and columns of the board are numbered from 11 to nn. Cell (x,y)(x,y) lies on the intersection of column number xx and row number yy.

Rook is a chess piece, that can in one turn move any number of cells vertically or horizontally. There are mm rooks (m

In one turn you can move one of the rooks any number of cells vertically or horizontally. Additionally, it shouldn't be attacked by any other rook after movement. What is the minimum number of moves required to place all the rooks on the main diagonal?

The main diagonal of the chessboard is all the cells (i,i)(i,i), where 

你可能感兴趣的:(图论——并查集)