---
id: 553
lang: en
translation_of: index.md
source_sha256: 92da0de4d829d513b7efe2eb4f8fa26f5ca10978f1b2c7f410df19826e31c90f
title: "BZOJ2140: Stable Marriage — Solution"
description: "Add a directed edge from man to woman for each marriage and from woman to man for each lover pair, then count the SCCs of size one."
tags: ["OI","Strongly Connected Components","Tarjan"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes: []
---

## Main Idea

For each marriage, add a directed edge from the man to the woman; for each lover relationship, add a directed edge from the woman to the man. Then just count the strongly connected components of size one.
