<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="th">
	<id>https://theory.cpe.ku.ac.th/wiki/index.php?action=history&amp;feed=atom&amp;title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552%2F%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_II%2F%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1</id>
	<title>418531 ภาคต้น 2552/โจทย์ปัญหาการโปรแกรมพลวัต II/เฉลยข้อ 1 - ประวัติรุ่นแก้ไข</title>
	<link rel="self" type="application/atom+xml" href="https://theory.cpe.ku.ac.th/wiki/index.php?action=history&amp;feed=atom&amp;title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552%2F%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_II%2F%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1"/>
	<link rel="alternate" type="text/html" href="https://theory.cpe.ku.ac.th/wiki/index.php?title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552/%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_II/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1&amp;action=history"/>
	<updated>2026-04-22T23:18:31Z</updated>
	<subtitle>ประวัติรุ่นแก้ไขของหน้านี้ในวิกิ</subtitle>
	<generator>MediaWiki 1.33.1</generator>
	<entry>
		<id>https://theory.cpe.ku.ac.th/wiki/index.php?title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552/%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_II/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1&amp;diff=7699&amp;oldid=prev</id>
		<title>Cardcaptor เมื่อ 14:50, 4 ตุลาคม 2552</title>
		<link rel="alternate" type="text/html" href="https://theory.cpe.ku.ac.th/wiki/index.php?title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552/%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_II/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1&amp;diff=7699&amp;oldid=prev"/>
		<updated>2009-10-04T14:50:11Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&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;th&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;←รุ่นแก้ไขก่อนหน้า&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;รุ่นแก้ไขเมื่อ 14:50, 4 ตุลาคม 2552&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-l24&quot; &gt;แถว 24:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;แถว 24:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;# สร้างอะเรย์ &amp;lt;math&amp;gt;M \,&amp;lt;/math&amp;gt; ให้มีขนาดใหญ่เท่ากับจำนวน vertex ในกราฟ และเซตให้ &amp;lt;math&amp;gt;M[w] = 0 \,&amp;lt;/math&amp;gt; สำหรับ vertex &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt; ทุกๆ vertex&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;# สร้างอะเรย์ &amp;lt;math&amp;gt;M \,&amp;lt;/math&amp;gt; ให้มีขนาดใหญ่เท่ากับจำนวน vertex ในกราฟ และเซตให้ &amp;lt;math&amp;gt;M[w] = 0 \,&amp;lt;/math&amp;gt; สำหรับ vertex &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt; ทุกๆ vertex&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;# ไล่ vertex &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; ทีละเวอร์เท็กซ์ โดยไล่จากค่า &amp;lt;math&amp;gt;L[x] \,&amp;lt;/math&amp;gt; น้อยไปยังค่า &amp;lt;math&amp;gt;L[x] \,&amp;lt;/math&amp;gt; มาก&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;# ไล่ vertex &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; ทีละเวอร์เท็กซ์ โดยไล่จากค่า &amp;lt;math&amp;gt;L[x] \,&amp;lt;/math&amp;gt; น้อยไปยังค่า &amp;lt;math&amp;gt;L[x] \,&amp;lt;/math&amp;gt; มาก&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; 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 class=&quot;diffchange diffchange-inline&quot;&gt;# &lt;/del&gt;พิจารณา edge &amp;lt;math&amp;gt;(x,w) \,&amp;lt;/math&amp;gt; ที่ออกจาก &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; ทุก edge  &lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;: &lt;/ins&gt;พิจารณา edge &amp;lt;math&amp;gt;(x,w) \,&amp;lt;/math&amp;gt; ที่ออกจาก &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; ทุก edge  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; 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 class=&quot;diffchange diffchange-inline&quot;&gt;## &lt;/del&gt;ถ้า &amp;lt;math&amp;gt;L[w] = L[x]+1 \,&amp;lt;/math&amp;gt; แล้ว เซตให้ &amp;lt;math&amp;gt;M[w] = M[w] + M[x] \,&amp;lt;/math&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;:: &lt;/ins&gt;ถ้า &amp;lt;math&amp;gt;L[w] = L[x]+1 \,&amp;lt;/math&amp;gt; แล้ว เซตให้ &amp;lt;math&amp;gt;M[w] = M[w] + M[x] \,&amp;lt;/math&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;เมื่ออัลกอริทึมทำงานเสร็จ เราจึงสามารถคืน &amp;lt;math&amp;gt;M[v] \,&amp;lt;/math&amp;gt; เป็นคำตอบได้&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;เมื่ออัลกอริทึมทำงานเสร็จ เราจึงสามารถคืน &amp;lt;math&amp;gt;M[v] \,&amp;lt;/math&amp;gt; เป็นคำตอบได้&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; 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 class=&quot;diffchange diffchange-inline&quot;&gt;ัอัลกอริทึมข้างบนทำงานโดยใช้เวลา &lt;/del&gt;&amp;lt;math&amp;gt;O(|V| + |E|) \,&amp;lt;/math&amp;gt; เนื่องจาก breadth first search ทำงานได้ในเวลา &amp;lt;math&amp;gt;O(|V|+|E|) \,&amp;lt;/math&amp;gt; และ loop ในข้อ 3 ก็ทำงานในเวลา &amp;lt;math&amp;gt;O(|V|+|E|) \,&amp;lt;/math&amp;gt; เช่นกันเนื่องจากมันเข้าถึง  edge แต่ละ edge เพียงครั้งเดียวเท่านั้น&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;อัลกอริทึมข้างบนทำงานโดยใช้เวลา &lt;/ins&gt;&amp;lt;math&amp;gt;O(|V| + |E|) \,&amp;lt;/math&amp;gt; เนื่องจาก breadth first search ทำงานได้ในเวลา &amp;lt;math&amp;gt;O(|V|+|E|) \,&amp;lt;/math&amp;gt; และ loop ในข้อ 3 ก็ทำงานในเวลา &amp;lt;math&amp;gt;O(|V|+|E|) \,&amp;lt;/math&amp;gt; เช่นกันเนื่องจากมันเข้าถึง  edge แต่ละ edge เพียงครั้งเดียวเท่านั้น&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Cardcaptor</name></author>
		
	</entry>
	<entry>
		<id>https://theory.cpe.ku.ac.th/wiki/index.php?title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552/%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_II/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1&amp;diff=7698&amp;oldid=prev</id>
		<title>158.108.183.136: หน้าที่ถูกสร้างด้วย &#039;สังเกตว่าในกราฟนี้ทุก edge มีความยาวเป็น 1 ดังนั้นเร…&#039;</title>
		<link rel="alternate" type="text/html" href="https://theory.cpe.ku.ac.th/wiki/index.php?title=418531_%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%95%E0%B9%89%E0%B8%99_2552/%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B8%9E%E0%B8%A5%E0%B8%A7%E0%B8%B1%E0%B8%95_II/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD_1&amp;diff=7698&amp;oldid=prev"/>
		<updated>2009-10-04T14:49:22Z</updated>

		<summary type="html">&lt;p&gt;หน้าที่ถูกสร้างด้วย &amp;#039;สังเกตว่าในกราฟนี้ทุก edge มีความยาวเป็น 1 ดังนั้นเร…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;หน้าใหม่&lt;/b&gt;&lt;/p&gt;&lt;div&gt;สังเกตว่าในกราฟนี้ทุก edge มีความยาวเป็น 1 ดังนั้นเราจึงาสามารถหา shortest path จาก u ไป v ได้ด้วย breadth first search (BFS)&lt;br /&gt;
&lt;br /&gt;
ในการแก้ปัญหาในโจทย์ เราจะพยายามแก้ปัญหาที่เป็นแนวทั่วไปมากขึ้น กล่าวคือเราจะไม่หาจำนวน shortest path ที่แตกต่างกันจาก &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;
แต่เราจะทำการหาคำนวณอะเรย์ &amp;lt;math&amp;gt;M[\cdot] \,&amp;lt;/math&amp;gt; โดยที่ &amp;lt;math&amp;gt;M[w] \,&amp;lt;/math&amp;gt; มีค่าเท่ากับจำนวน shortest path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปยัง &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt;&lt;br /&gt;
เมื่อ &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt; เป็น vertex ใดๆ ในกราฟ&lt;br /&gt;
&lt;br /&gt;
อันดับแรก สังเกตว่า &amp;lt;math&amp;gt;M[u] = 1 \,&amp;lt;/math&amp;gt; เนื่องจาก shortest path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปยัง &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; มีอยู่ path เดียวคือ path ความยาว 0 ที่เริ่มที่ &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; แล้วไม่เคลื่อนต่อไปไหน&lt;br /&gt;
&lt;br /&gt;
ต่อไป ให้ &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt; เป็น vertex ใดๆ ในกราฟ สมมติว่า shortest path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปยัง &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt; มีความยาว &amp;lt;math&amp;gt;\ell \,&amp;lt;/math&amp;gt; edge &lt;br /&gt;
เราจะได้ว่า&lt;br /&gt;
: &amp;lt;math&amp;gt;M[w] = M[x_1] + M[x_2] + \dotsb + M[x_k]&amp;lt;/math&amp;gt; (*)&lt;br /&gt;
เมื่อ &amp;lt;math&amp;gt;x_1, x_2, \ldots, x_k \,&amp;lt;/math&amp;gt; คือ vertex ทั้งหมดที่&lt;br /&gt;
# ความยาวของ shortest path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปยัง &amp;lt;math&amp;gt;x_i \,&amp;lt;/math&amp;gt; มีค่าเท่ากับ &amp;lt;math&amp;gt;\ell-1 \,&amp;lt;/math&amp;gt; และ&lt;br /&gt;
# มี edge &amp;lt;math&amp;gt;\{ x_i, w \} \,&amp;lt;/math&amp;gt; อยู่ในกราฟ สำหรับทุกๆ &amp;lt;math&amp;gt;i \,&amp;lt;/math&amp;gt;&lt;br /&gt;
ที่เป็นเช่นนี้เพราะว่าสำหรับ path ความยาว &amp;lt;math&amp;gt;\ell \,&amp;lt;/math&amp;gt; จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปถึง &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt; ทุก path จะมี vertex สุดท้ายก่อนจะไปถึง &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt;&lt;br /&gt;
สมมติให้ vertex สุดท้ายนั้นเป็น &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; เราจะได้ว่า&lt;br /&gt;
: ความยาวของ shortest path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปยัง &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; จะต้องเป็น &amp;lt;math&amp;gt;\ell-1 \,&amp;lt;/math&amp;gt;&lt;br /&gt;
(ัอันดับแรก ความยาวของ shortest path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปยัง &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; จะมีค่ามากที่สุดเท่ากับ &amp;lt;math&amp;gt;\ell - 1 \,&amp;lt;/math&amp;gt; เนื่องจาก path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปถึง &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; ก่อนที่จะไป &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt; มีความยาว &amp;lt;math&amp;gt;\ell-1 \,&amp;lt;/math&amp;gt; อยู่แล้ว อันดับที่สอง shortest path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปถึง &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; จะสั้นกว่า &amp;lt;math&amp;gt;\ell-1 \,&amp;lt;/math&amp;gt; ไม่ได้ เนื่องจากถ้ามันสั้นกว่านั้นความยาวของ shortest path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปถึง &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt; ก็จะสั้นลงด้วย) &lt;br /&gt;
&lt;br /&gt;
ด้วยเหตุนี้ สำหรับ shortest path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปถึง &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; หนึ่ง path จะทำให้เกิด shortest path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปถึง &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt; หนึ่ง path ด้วย (กล่าวคือเราเดินจาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ไปถึง &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; แล้วเดินต่อจาก &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; ไปยัง &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt; โดยผ่าน edge &amp;lt;math&amp;gt;\{x, w\} \,&amp;lt;/math&amp;gt;) สมการ (*) จีงเป็นความจริง&lt;br /&gt;
&lt;br /&gt;
จากสมการ (*) เราจึงสามารถคำนวณอะเรย์ &amp;lt;math&amp;gt;M[w] \,&amp;lt;/math&amp;gt; ได้ดังต่อไปนี้&lt;br /&gt;
# รัน breadth first search บนกราฟโดยเริ่มจาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; แล้วให้แต่ละ vertex &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt;  แต่ละ vertex จำระดับของมัน (ซึ่งมีค่าเท่ากับความยาวของ shortest path จาก &amp;lt;math&amp;gt;u \,&amp;lt;/math&amp;gt; ถึง &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt;) ไว้ในอะเรย์ &amp;lt;math&amp;gt;L[w] \,&amp;lt;/math&amp;gt;&lt;br /&gt;
# สร้างอะเรย์ &amp;lt;math&amp;gt;M \,&amp;lt;/math&amp;gt; ให้มีขนาดใหญ่เท่ากับจำนวน vertex ในกราฟ และเซตให้ &amp;lt;math&amp;gt;M[w] = 0 \,&amp;lt;/math&amp;gt; สำหรับ vertex &amp;lt;math&amp;gt;w \,&amp;lt;/math&amp;gt; ทุกๆ vertex&lt;br /&gt;
# ไล่ vertex &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; ทีละเวอร์เท็กซ์ โดยไล่จากค่า &amp;lt;math&amp;gt;L[x] \,&amp;lt;/math&amp;gt; น้อยไปยังค่า &amp;lt;math&amp;gt;L[x] \,&amp;lt;/math&amp;gt; มาก&lt;br /&gt;
## พิจารณา edge &amp;lt;math&amp;gt;(x,w) \,&amp;lt;/math&amp;gt; ที่ออกจาก &amp;lt;math&amp;gt;x \,&amp;lt;/math&amp;gt; ทุก edge &lt;br /&gt;
### ถ้า &amp;lt;math&amp;gt;L[w] = L[x]+1 \,&amp;lt;/math&amp;gt; แล้ว เซตให้ &amp;lt;math&amp;gt;M[w] = M[w] + M[x] \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
เมื่ออัลกอริทึมทำงานเสร็จ เราจึงสามารถคืน &amp;lt;math&amp;gt;M[v] \,&amp;lt;/math&amp;gt; เป็นคำตอบได้&lt;br /&gt;
&lt;br /&gt;
ัอัลกอริทึมข้างบนทำงานโดยใช้เวลา &amp;lt;math&amp;gt;O(|V| + |E|) \,&amp;lt;/math&amp;gt; เนื่องจาก breadth first search ทำงานได้ในเวลา &amp;lt;math&amp;gt;O(|V|+|E|) \,&amp;lt;/math&amp;gt; และ loop ในข้อ 3 ก็ทำงานในเวลา &amp;lt;math&amp;gt;O(|V|+|E|) \,&amp;lt;/math&amp;gt; เช่นกันเนื่องจากมันเข้าถึง  edge แต่ละ edge เพียงครั้งเดียวเท่านั้น&lt;/div&gt;</summary>
		<author><name>158.108.183.136</name></author>
		
	</entry>
</feed>