---
id: 552
lang: en
translation_of: index.md
source_sha256: dc5918601d2003866d6e531793c755095c984e2d61c6aab3083bc4c87c65df08
title: "Graph Theory Study Notes"
description: "In a directed graph, each vertex belongs to exactly one strongly connected component."
tags: ["OI","Graph Theory","Strongly Connected Components","Tarjan","Network Flow","Minimum Cut","Maximum Flow","Min-Cost Flow"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "弾栈 (a typo for 弹栈) rendered as “pop the stack”."
  - "子树大于二 kept literally as “more than two subtrees”, although the code checks child >= 2."
  - "The problem names [USACO2006NOV]Asteriod and [Usaco2005 jan]Muddy Fields are kept exactly as written, including the misspelling Asteriod."
---

## Strongly Connected Components

### Some Properties

1. In a directed graph, each vertex belongs to exactly one strongly connected component.
2. Strongly connected components are transitive.
3. A maximal strongly connected component means a strongly connected component that cannot be enlarged any further.

### Some Details of Tarjan's Algorithm

1. When a node's DFN equals its LOW, a strongly connected component has been found, so pop the stack.

### Some Example Problems

[P2002: Message Spread — Solution](../../2018/446-p2002-message-spread/index.en.html)

## Finding Cut Vertices

Similar to the Tarjan algorithm above, as long as $dfn[u]\leq low[u]$, this vertex can be considered a cut vertex. Intuition: if the downstream vertices cannot reach the upstream vertices with smaller dfn except by paths through vertex u, then this is a cut vertex. But we also need to consider the case where vertex $u$ is the root, because if vertex $u$ is the root, then it counts as a cut vertex as long as it has more than two subtrees, since connectivity between the subtrees has to go through the root as a hub.

Code for the [template problem](https://www.luogu.org/problemnew/show/P3388):

```cpp
// P3388.cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 20010, MAX_M = 100010;
int head[MAX_N], current, n, m, tmpx, tmpy, low[MAX_N], dfn[MAX_N], tot;
bool ans[MAX_N];
struct edge
{
    int to, nxt;
} edges[MAX_M << 1];
void addpath(int src, int dst)
{
    edges[current].to = dst, edges[current].nxt = head[src];
    head[src] = current++;
}
void tarjan(int u, int fa)
{
    low[u] = dfn[u] = ++tot;
    int child = 0;
    for (int i = head[u]; i != -1; i = edges[i].nxt)
    {
        if (!dfn[edges[i].to])
        {
            tarjan(edges[i].to, fa), low[u] = min(low[u], low[edges[i].to]);
            if (low[edges[i].to] >= dfn[u] && u != fa)
                ans[u] = true;
            if (u == fa)
                child++;
        }
        low[u] = min(low[u], dfn[edges[i].to]);
    }
    if (child >= 2 && u == fa)
        ans[u] = true;
}
int main()
{
    memset(head, -1, sizeof(head));
    scanf("%d%d", &n, &m);
    int cnt = 0;
    for (int i = 1; i <= m; i++)
        scanf("%d%d", &tmpx, &tmpy), addpath(tmpx, tmpy), addpath(tmpy, tmpx);
    for (int i = 1; i <= n; i++)
        if (!dfn[i])
            tarjan(i, i);
    for (int i = 1; i <= n; i++)
        if (ans[i])
            cnt++;
    printf("%d\n", cnt);
    for (int i = 1; i <= n; i++)
        if (ans[i])
            printf("%d ", i);
    return 0;
}
```

## Biconnected Components

### Vertex-Biconnected Components

Definition: in an undirected graph, for a pair of vertices $u,v$, if they stay connected after deleting any **one** vertex other than $u,v$ from the graph, then this pair is called a vertex-biconnected component.

### Edge-Biconnected Components

Definition: in an undirected graph, for a pair of vertices $u,v$, if $u,v$ stay connected after deleting any one edge from the graph, then it is called an edge-biconnected component.

## Bipartite Graphs

<https://www.renfei.org/blog/bipartite-matching.html>

### Properties

> **In a bipartite graph, choosing the fewest vertices such that these vertices are incident to all the edges (covering all the edges) is called a minimum vertex cover.**

Minimum vertex cover of a bipartite graph = maximum matching of the bipartite graph

Maximum independent set of a bipartite graph = total number of vertices - maximum total matching of the bipartite graph

Example problems: [\[USACO2006NOV\]Asteriod](../558-poj3041-usaco2006nov-asteroid/index.en.html), \[Usaco2005 jan\]Muddy Fields

### Hungarian Algorithm

Template link: [P3386 \[Template\] Bipartite Matching](https://www.luogu.org/problemnew/show/P3386://P368)

```cpp
bool dfs(int u, int tm)
{
    for (int i = head[u]; i != -1; i = edges[i].nxt)
    {
        int to = edges[i].to;
        if (dfn[to] != tm)
        {
            dfn[to] = tm;
            if ((!match[to]) || dfs(match[to], tm))
            {
                match[to] = u;
                return true;
            }
        }
    }
    return false;
}
```

Personally, I think this is a rather ingenious way to write it: it combines “keep matching” and “negotiate upward” perfectly, which is really excellent.

## 2-SAT

This model can be used to find the solution set of variables under multiple constraints. You can derive feasible relations from certain contradiction relations and add them as directed edges, then just color with Tarjan.

Example problem: [HDU3062: Party — Solution](../563-hdu3062-party/index.en.html)
