ToJ 3345. Key match of Chinese chess

Source: Internet
Author: User

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 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.