FMATCH - Fast Maximum Matching

FJ has N (1 ≤ N ≤ 50,000) cows and M (1 ≤ M ≤ 50,000) bulls. Given a list of P (1 ≤ P ≤ 150,000) potential matches between a cow and a bull, compute the greatest number of pairs that can be matched. Of course, a cow can be matched to at most one bull, and vice versa.

Input

The first line contains three integers, N, M, and P. Each of the next P lines contains two integers A (1 ≤ A ≤ N) and B (1 ≤ B ≤ M), denoting that cow A can be matched with bull B.

Output

Print a single integer that is the maximum number of pairs that can be obtained.

Example

Input:
5 4 6
5 2
1 2
4 3
3 1
2 2
4 4

Output:
3

Cow 1 can be matched to bull 2, cow 3 to bull 1, and cow 4 to bull 3.

Original problem: https://www.spoj.com/problems/MATCHING/.


Được gửi lên bởi:Race with time
Ngày:2009-04-13
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:Neal Wu - SPOJ

hide comments
2020-10-26 04:43:55
Comment bên dưới là của Thái Bá Hưng A2K48,không phải của Thanh Tuyển
2020-10-26 04:40:35
Hom nay Thanh Tuyen A2K48 hoc cap ghep
Tuong ko kho hoa ra kho khong tuong :D
2017-03-20 19:06:32
cạp ghép mà n m thế kia ai chơi nhỉ ??
2015-06-11 05:14:36 Nguyen Tri Nhan
Leave a Comment
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.