Gold
Batch
Editorial available
River Rope Rescue
/river-rope-rescue
Version
v1
Published
Apr 23, 2026, 10:56 PM
Updated
Apr 23, 2026, 10:56 PM
Testsets
1
Statement
Rendered as plain statement text from the published version.
# River Rope Rescue
## Problem
Bessie has herded the MOOSACO cattle to the left bank of a river, where disaster has struck! There are $L$ cows stranded on the left bank and $R$ rescue posts positioned on the right bank.
Each cow can only reach certain rescue posts via rope bridges. A rope bridge connects cow $i$ to post $j$ if an edge $(i, j)$ exists in the input. Each cow can be rescued at most once, and each rescue post can save at most one cow.
Determine the **maximum number of cows that can be rescued**.
## Input
The first line contains two integers $L$ and $R$ ($1 \le L, R \le 100$), the number of cows and rescue posts.
The next lines contain edges describing which cows can reach which posts. Each edge is given as two integers $i$ and $j$ where cow $i$ can reach post $j$. The input ends when there are no more edges (or you may read until EOF).
## Output
Output a single integer: the maximum number of cows that can be rescued.
## Constraints
- $1 \le L, R \le 100$
- Each cow and post pair appears at most once
- Edge values are in range $[1, L]$ for cows and $[1, R]$ for posts
## Sample Input
```
3 3
1 1
1 2
2 2
3 2
3 3
```
## Sample Output
```
3
```
## Explanation
With 3 cows and 3 rescue posts:
- Cow 1 can reach posts 1 and 2
- Cow 2 can reach post 2
- Cow 3 can reach posts 2 and 3
We can rescue all 3 cows:
- Cow 1 uses post 1
- Cow 2 uses post 2
- Cow 3 uses post 3
The maximum number of rescued cows is **3**.