惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
I
InfoQ
Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Recent Announcements
Recent Announcements
GbyAI
GbyAI
爱范儿
爱范儿
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
美团技术团队
罗磊的独立博客
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
M
MIT News - Artificial intelligence
D
Docker
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs
博客园 - 叶小钗

Louis C Deng's Blog

RoPE: Properties, Patterns, and Long-Context Behavior CS336 Assignment 1: Large Language Model Training and Inference CS231n Lecture Note: Generative Models CS231n Lecture Note: Self-Supervised Learning CS231n Lecture Note: Large Scale Distributed Training 自動微分 | DIY 實現自己的 PyTorch From RNNs to Transformers CS231n Lecture Note VII: Recurrent Neural Networks Uncovering Batch & Layer Normalization CS231n Lecture Note VI: CNN Architectures and Training CS231n Lecture Note V: Convolution Neural Networks Basics Demystifying Softmax Loss: A Step-by-Step Derivation for Linear Classifiers Backpropagation: A Vector Calculus Perspective CS231n Lecture Note IV: Neural Networks and Backpropagation CS231n Lecture Note III: Optimization CS231n Lecture Note II: Linear Classifiers CS231n Lecture Note I: Image Classification CSAPP Cache Lab II: Optimizing Matrix Transposition CSAPP Cache Lab I: Let's simulate a cache memory! CS188 Search Lecture Notes III CS188 Search Lecture Notes II How to Use TouchID for Sudo Commands on macOS CS188 Search Lecture Notes I RECAP2025: 留白 CSAPP Bomb Lab 解析 x64 暫存器速查表 CSAPP Data Lab 解析 矩陣的 Modified Gram Schmidt 方法 聊一聊位掩碼(Bit Mask) 整數溢位與未定義行為
割點 Tarjan 演算法
Louis C Deng · 2022-12-05 · via Louis C Deng's Blog

最近學習圖論,寫篇題解記錄一下。

定義

  • 對於一個無向圖,如果把一個點刪除後這個圖的極大連通分量數增加了,那麼這個點就是這個圖的割點(又稱割頂)。

這篇部落格主要介紹,Tarjan 演算法用於求 割點。

割點

Tarjan 演算法,記錄 節點訪問時間戳 dfn,節點能夠回溯到的最早的點的時間戳 low

對於某一點:

  1. 如果這個點是根節點,且有兩個以上與它相連的連通分量,那這個點就是割點。
  2. 如果某個點後繼是一個連通分量,而這個點不是根節點,那這個點是割點。

第一種情況

我們需要記錄根節點 fa,在遍歷的時候,如果重複訪問到了 fa,說明找到了 fa 下面的一個連通分量。

第二種情況

設當前點 s,對於訪問的下一個節點 y

如果 low[y] >= dfn[s],說明這個點下面有一個連通分量。

注:這裡類似於 Tarjan 求 SCC 時,我們所做的 min(low[s],dfn[y])

程式碼

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void tarjan(int s, int fa){
dfn[s] = low[s] = ++cc;
int child = 0;
for(int i = head[s]; i!=-1; i=NDS[i].next){
int y = NDS[i].to;
if(!dfn[y]){
tarjan(y,fa);
low[s] = min(low[s], low[y]);
if(low[y]>=dfn[s] && s != fa)
cut[s] = 1;
if(s==fa)
child++;
}
low[s] = min(low[s], dfn[y]);
}
if(child>=2&&s==fa){
cut[s] = 1;
}
}