<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://www.33dai.wiki/index.php?action=history&amp;feed=atom&amp;title=11-%E5%9B%BE%E8%AE%BA%2F04-%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F</id>
	<title>11-图论/04-拓扑排序 - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://www.33dai.wiki/index.php?action=history&amp;feed=atom&amp;title=11-%E5%9B%BE%E8%AE%BA%2F04-%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F"/>
	<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=11-%E5%9B%BE%E8%AE%BA/04-%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F&amp;action=history"/>
	<updated>2026-05-20T22:11:40Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=11-%E5%9B%BE%E8%AE%BA/04-%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F&amp;diff=442&amp;oldid=prev</id>
		<title>33DAI：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=11-%E5%9B%BE%E8%AE%BA/04-%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F&amp;diff=442&amp;oldid=prev"/>
		<updated>2026-05-20T18:24:07Z</updated>

		<summary type="html">&lt;p&gt;批量导入三三文档&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 18:24的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l82&quot;&gt;第82行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第82行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:图论]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:图论]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:三三文档]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:三三文档]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key my_wiki:diff:1.41:old-415:rev-442:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=11-%E5%9B%BE%E8%AE%BA/04-%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F&amp;diff=415&amp;oldid=prev</id>
		<title>33DAI：​导入1个版本</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=11-%E5%9B%BE%E8%AE%BA/04-%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F&amp;diff=415&amp;oldid=prev"/>
		<updated>2026-05-20T18:12:24Z</updated>

		<summary type="html">&lt;p&gt;导入1个版本&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年5月20日 (三) 18:12的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;zh-Hans-CN&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;（没有差异）&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>33DAI</name></author>
	</entry>
	<entry>
		<id>https://www.33dai.wiki/index.php?title=11-%E5%9B%BE%E8%AE%BA/04-%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F&amp;diff=414&amp;oldid=prev</id>
		<title>-&gt;Importer：​批量导入三三文档</title>
		<link rel="alternate" type="text/html" href="https://www.33dai.wiki/index.php?title=11-%E5%9B%BE%E8%AE%BA/04-%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F&amp;diff=414&amp;oldid=prev"/>
		<updated>2026-05-20T16:50:33Z</updated>

		<summary type="html">&lt;p&gt;批量导入三三文档&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== 拓扑排序 ==&lt;br /&gt;
&lt;br /&gt;
拓扑排序只适用于&amp;#039;&amp;#039;&amp;#039;有向无环图（DAG）&amp;#039;&amp;#039;&amp;#039;，将顶点排序成线性序列，使得每条边 &amp;lt;math&amp;gt;u \to v&amp;lt;/math&amp;gt; 中 &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; 排在 &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; 前面。&lt;br /&gt;
&lt;br /&gt;
=== 应用场景 ===&lt;br /&gt;
&lt;br /&gt;
* 课程先修关系（A 是 B 的先修课）&lt;br /&gt;
* 编译依赖顺序&lt;br /&gt;
* 任务调度&lt;br /&gt;
&lt;br /&gt;
=== BFS 实现（Kahn 算法） ===&lt;br /&gt;
&lt;br /&gt;
每次选入度为 &amp;lt;math&amp;gt;0&amp;lt;/math&amp;gt; 的点输出并删除：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
vector&amp;lt;int&amp;gt; g[MAXN];&lt;br /&gt;
int indeg[MAXN]; // 入度&lt;br /&gt;
&lt;br /&gt;
vector&amp;lt;int&amp;gt; topo_sort(int n)&lt;br /&gt;
{&lt;br /&gt;
    vector&amp;lt;int&amp;gt; res;&lt;br /&gt;
    queue&amp;lt;int&amp;gt; q;&lt;br /&gt;
&lt;br /&gt;
    for (int i = 1; i &amp;lt;= n; i++)&lt;br /&gt;
        if (indeg[i] == 0)&lt;br /&gt;
            q.push(i);&lt;br /&gt;
&lt;br /&gt;
    while (!q.empty())&lt;br /&gt;
    {&lt;br /&gt;
        int u = q.front();&lt;br /&gt;
        q.pop();&lt;br /&gt;
        res.push_back(u);&lt;br /&gt;
&lt;br /&gt;
        for (int v : g[u])&lt;br /&gt;
        {&lt;br /&gt;
            indeg[v]--;&lt;br /&gt;
            if (indeg[v] == 0)&lt;br /&gt;
                q.push(v);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // 若 res.size() &amp;lt; n，说明图中有环&lt;br /&gt;
    return res;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DFS 实现 ===&lt;br /&gt;
&lt;br /&gt;
后序遍历的逆序即为拓扑序：&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
vector&amp;lt;int&amp;gt; g[MAXN];&lt;br /&gt;
bool vis[MAXN], on_path[MAXN];&lt;br /&gt;
vector&amp;lt;int&amp;gt; topo;&lt;br /&gt;
&lt;br /&gt;
bool dfs(int u)&lt;br /&gt;
{&lt;br /&gt;
    vis[u] = true;&lt;br /&gt;
    on_path[u] = true;&lt;br /&gt;
    for (int v : g[u])&lt;br /&gt;
    {&lt;br /&gt;
        if (!vis[v])&lt;br /&gt;
        {&lt;br /&gt;
            if (!dfs(v)) return false;&lt;br /&gt;
        }&lt;br /&gt;
        else if (on_path[v])&lt;br /&gt;
            return false; // 有环&lt;br /&gt;
    }&lt;br /&gt;
    on_path[u] = false;&lt;br /&gt;
    topo.push_back(u);&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// 调用&lt;br /&gt;
for (int i = 1; i &amp;lt;= n; i++)&lt;br /&gt;
    if (!vis[i])&lt;br /&gt;
        dfs(i);&lt;br /&gt;
reverse(topo.begin(), topo.end()); // 逆序即为拓扑序&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:图论]]&lt;br /&gt;
[[Category:三三文档]]&lt;br /&gt;
&lt;/div&gt;</summary>
		<author><name>-&gt;Importer</name></author>
	</entry>
</feed>