3345. Chinese chess
Time Limit: 20.0 seconds memory limit: 65536 K
Total runs: 426 accepted runs: 47
Winnie is very interested in Chinese chess. Now, let's consider a game which is similar to it. There is
N*
MChess board, we hope we can put Rooks as more as possible. But just a certain number
Postions can be put rooks on. one Rook can attack another if they are in the same row or column. now you may think this is a very simple problem for you. but as very whuacmers know, Winnie is edevil enough to cheat you. let's consider some positions called critical
Postions. If we don't put rook on the critical position, the maximum number of rook we can put on this chess board will reduce. How many critical positions on the chess board?
Input
Input will contain multiple test cases. The first line contains three numbersN,M,K(N,M≤ 10000,K≤ 100000) which indicate height, width and number of positions which can be put rook on. Then nextKLines
Follow, each contains two integerXAnsYWhich indicate we can put rook onXTh row,YTh Column.
Output
Output as follow:
BoardTHaveCImportant blanksLChessmen.
CIndicate the number of critical positions ansLIndicate the maximum Rooks can be put.
Sample Input
3 3 41 21 32 12 23 3 41 21 32 13 2
Sample output
Board 1 have 0 important blanks for 2 chessmen.Board 2 have 3 important blanks for 3 chessmen.
Hint:Huge input, use scanf please.
Question: there are many points on the board. I asked at least a few pieces can be set to eat them. I also asked which pieces are placed in a fixed position. Otherwise, some points cannot be eaten.
Key match:
First, find the maximum match.
Check whether the two endpoints U and V of each matching edge correspond to a unique matching edge,
Optimization will time out. Only by reading other people's code can we find that this optimization can be achieved. Amazing
There are two optimizations.
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <vector> using namespace STD; const int maxn = 10009; int cover [maxn], pre [maxn], son [maxn], flag [maxn]; vector <int> head1 [maxn], head2 [maxn]; int nodeu, nodev; int findx (int u) {// find the augmented path for (INT I = 0; I