AlgoUniversity
  • Go Back
Discussion
Watchmen Trouble :

Author

Yash Sahijwani

Difficulty Level : Hard

Submissions : 203

Asked In : Sprinklr

Marks :100

: 1 | : 0

A river has $$$N$$$ checkpoints on its left side and $$$M$$$ checkpoints on its right side. $$$P$$$ bridges are built connecting checkpoints across the river. Guards needs to be placed on checkpoints and a guard can protect all the bridges on which this checkpoint is present. There can be more than one guard to protect a single bridge.

Find the minimum number of guards required to protect all the bridges over the river.

Input

The first line of input consists of 2 space separated integers $$$N$$$ and $$$M$$$ $$$-$$$ the number of checkpoints on the left and right side of the river respectively $$$(1 \leq N, M, \leq 100)$$$. The second line of input consists of a single integer $$$P$$$ $$$-$$$ the total number of bridges across the river $$$(1 \leq P \leq 100)$$$. Then the next $$$P$$$ lines, each consist of 2 space separated integers $$$u$$$, $$$v$$$ denoting that there is a bridge between $$$u_{th}$$$ checkpoint on the left side and $$$v_{th}$$$ checkpoint on the right side $$$(1 \leq u \leq N)$$$ $$$(1 \leq v \leq M)$$$.

Output

The output should consist of a single integer $$$-$$$ the minimum number of guards required to protect all the bridges over the river.

Example

Input
4 3
4
1 3
1 2
2 2
4 1
Output
3

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.