<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>https://acm.khpnets.info/w39/index.php?action=history&amp;feed=atom&amp;title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F</id>
	<title>Heavy-light-декомпозиция - История изменений</title>
	<link rel="self" type="application/atom+xml" href="https://acm.khpnets.info/w39/index.php?action=history&amp;feed=atom&amp;title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F"/>
	<link rel="alternate" type="text/html" href="https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;action=history"/>
	<updated>2026-05-13T12:36:27Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;diff=2948&amp;oldid=prev</id>
		<title>Ctrlalt в 00:43, 15 февраля 2026</title>
		<link rel="alternate" type="text/html" href="https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;diff=2948&amp;oldid=prev"/>
		<updated>2026-02-15T00:43:22Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;amp;diff=2948&amp;amp;oldid=2947&quot;&gt;Внесённые изменения&lt;/a&gt;</summary>
		<author><name>Ctrlalt</name></author>
	</entry>
	<entry>
		<id>https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;diff=2947&amp;oldid=prev</id>
		<title>Ctrlalt в 22:35, 14 февраля 2026</title>
		<link rel="alternate" type="text/html" href="https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;diff=2947&amp;oldid=prev"/>
		<updated>2026-02-14T22:35:34Z</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;ru&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;Версия от 22:35, 14 февраля 2026&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-l62&quot;&gt;Строка 62:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Строка 62:&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;   &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;   &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;          for (int to : graph[v])&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;          for (int to : graph[v])&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;              if (to != &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;p&lt;/del&gt;)&lt;/div&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;              if (to != &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;parent[v]&lt;/ins&gt;)&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;                  subtreeSize[v] += dfs(to, v);&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;                  subtreeSize[v] += dfs(to, v);&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;   &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;   &lt;/div&gt;&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-l86&quot;&gt;Строка 86:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Строка 86:&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;                  maxTo = to;&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;                  maxTo = to;&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;   &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;   &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;          for (int to : graph[v]) &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{&lt;/del&gt;&lt;/div&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;          for (int to : graph[v])&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;              if (to &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=&lt;/del&gt;= parent[v])&lt;/div&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;              if (to &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;!&lt;/ins&gt;= parent[v])&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;continue;&lt;/del&gt;&lt;/div&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;                  &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;buildPath&lt;/ins&gt;(&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;to, &lt;/ins&gt;to == maxTo &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;? &lt;/ins&gt;pathIndex &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;: &lt;/ins&gt;paths.size());&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;             if &lt;/del&gt;(to == maxTo&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;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;                 buildPath(to, &lt;/del&gt;pathIndex&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;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;             else&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;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;                 buildPath(to, &lt;/del&gt;paths.size());&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;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;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;      }&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;      }&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;   &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;   &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ctrlalt</name></author>
	</entry>
	<entry>
		<id>https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;diff=2946&amp;oldid=prev</id>
		<title>Ctrlalt: /* Ссылки */</title>
		<link rel="alternate" type="text/html" href="https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;diff=2946&amp;oldid=prev"/>
		<updated>2026-02-14T22:29:20Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Ссылки&lt;/span&gt;&lt;/span&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;ru&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;Версия от 22:29, 14 февраля 2026&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-l125&quot;&gt;Строка 125:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Строка 125:&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;br/&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;br/&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;== Ссылки ==&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;== Ссылки ==&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;http&lt;/del&gt;://e-maxx.ru/algo/heavy_light e-maxx.ru &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;mdash; &lt;/del&gt;Heavy-light декомпозиция]&lt;/div&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Теория:&lt;/ins&gt;&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;http&lt;/del&gt;://blog.anudeep2011.com/heavy-light-decomposition/ blog.anudeep2011.com &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;mdash; &lt;/del&gt;Heavy Light Decomposition]&lt;/div&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;https&lt;/ins&gt;://e-maxx.ru/algo/heavy_light e-maxx.ru &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;— &lt;/ins&gt;Heavy-light декомпозиция]&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;http&lt;/del&gt;://github.com/indy256/codelibrary/blob/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;master&lt;/del&gt;/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;java&lt;/del&gt;/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;src&lt;/del&gt;/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;HeavyLight&lt;/del&gt;.&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;java CodeLibrary &amp;amp;mdash; Heavy-light tree decomposition for edges or vertices&lt;/del&gt;]&lt;/div&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;https://cp-algorithms.com/graph/hld.html cp-algorithms.com — Heavy-light decomposition]&lt;/ins&gt;&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;http&lt;/del&gt;://github.com/ADJA/algos/blob/master/Graphs/HLD.cpp &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Algos &amp;amp;mdash; Heavy-light decomposition with segment trees in paths&lt;/del&gt;]&lt;/div&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* [https://algorithmica.org/ru/hld algorithmica.org — Heavy-light декомпозиция]&lt;/ins&gt;&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;http&lt;/del&gt;://github.com/ADJA/algos/blob/master/Graphs/LCAHLD.cpp &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Algos &amp;amp;mdash; Finding LCA (Least common ancestor) of two vertices in the tree&lt;/del&gt;. &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Uses heavy-light decomposition&lt;/del&gt;]&lt;/div&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* [https://codeforces.com/blog/entry/12239 codeforces.com — Heavy-light decompositon — это может быть просто!]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* [https://codeforces.com/blog/entry/81317 codeforces.com — Hybrid Tutorial #-1: Heavy-Light Decomposition]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* [https://web.archive.org/web/20221128105153/https&lt;/ins&gt;://blog.anudeep2011.com/heavy-light-decomposition/ blog.anudeep2011.com &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;— Heavy Light Decomposition]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* [https://usaco.guide/plat/hld usaco.guide — &lt;/ins&gt;Heavy&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/ins&gt;Light Decomposition]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Код:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;https&lt;/ins&gt;://github.com/indy256/codelibrary/blob/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;main/cpp/structures/heavy_light_decomposition.cpp codelibrary&lt;/ins&gt;/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;cpp&lt;/ins&gt;/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;structures&lt;/ins&gt;/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;heavy_light_decomposition&lt;/ins&gt;.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;cpp&lt;/ins&gt;]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;https&lt;/ins&gt;://github.com/ADJA/algos/blob/master/Graphs/HLD.cpp &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;algos/Graphs/HLD.cpp&lt;/ins&gt;]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&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: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;https&lt;/ins&gt;://github.com/ADJA/algos/blob/master/Graphs/LCAHLD.cpp &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;algos/Graphs/LCAHLD&lt;/ins&gt;.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;cpp&lt;/ins&gt;]&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;br/&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;br/&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;[[Категория:Учебный курс «Алгоритмы и структуры данных»]]&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;[[Категория:Учебный курс «Алгоритмы и структуры данных»]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ctrlalt</name></author>
	</entry>
	<entry>
		<id>https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;diff=2943&amp;oldid=prev</id>
		<title>Ctrlalt в 21:58, 14 февраля 2026</title>
		<link rel="alternate" type="text/html" href="https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;diff=2943&amp;oldid=prev"/>
		<updated>2026-02-14T21:58:56Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;amp;diff=2943&amp;amp;oldid=1070&quot;&gt;Внесённые изменения&lt;/a&gt;</summary>
		<author><name>Ctrlalt</name></author>
	</entry>
	<entry>
		<id>https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;diff=1070&amp;oldid=prev</id>
		<title>Ctrlalt: Новая страница: « #include &lt;stdio.h&gt;  #include &lt;vector&gt;  #include &lt;queue&gt;  #include &lt;set&gt;  #include &lt;map&gt;  #include &lt;algorithm&gt;  #include &lt;iostream&gt;  using namespace std;   class …»</title>
		<link rel="alternate" type="text/html" href="https://acm.khpnets.info/w39/index.php?title=Heavy-light-%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%B7%D0%B8%D1%86%D0%B8%D1%8F&amp;diff=1070&amp;oldid=prev"/>
		<updated>2014-11-15T14:24:22Z</updated>

		<summary type="html">&lt;p&gt;Новая страница: « #include &amp;lt;stdio.h&amp;gt;  #include &amp;lt;vector&amp;gt;  #include &amp;lt;queue&amp;gt;  #include &amp;lt;set&amp;gt;  #include &amp;lt;map&amp;gt;  #include &amp;lt;algorithm&amp;gt;  #include &amp;lt;iostream&amp;gt;  using namespace std;   class …»&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt; #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;vector&amp;gt;&lt;br /&gt;
 #include &amp;lt;queue&amp;gt;&lt;br /&gt;
 #include &amp;lt;set&amp;gt;&lt;br /&gt;
 #include &amp;lt;map&amp;gt;&lt;br /&gt;
 #include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
 #include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 using namespace std;&lt;br /&gt;
&lt;br /&gt;
 class ST {&lt;br /&gt;
     int *t, size;&lt;br /&gt;
     void build(int v, int vl, int vr) {&lt;br /&gt;
         if (vl == vr) {&lt;br /&gt;
             t[v] = 0;&lt;br /&gt;
             return;&lt;br /&gt;
         }&lt;br /&gt;
         int vm = vl + (vr - vl) / 2;&lt;br /&gt;
         build(2 * v + 1, vl, vm);&lt;br /&gt;
         build(2 * v + 2, vm + 1, vr);&lt;br /&gt;
         t[v] = max(t[2 * v + 1], t[2 * v + 2]);&lt;br /&gt;
     }&lt;br /&gt;
     int query(int v, int vl, int vr, int l, int r) {&lt;br /&gt;
         if (r &amp;lt; vl || vr &amp;lt; l)&lt;br /&gt;
             return -(1 &amp;lt;&amp;lt; 30);&lt;br /&gt;
         if (l &amp;lt;= vl &amp;amp;&amp;amp; vr &amp;lt;= r)&lt;br /&gt;
             return t[v];&lt;br /&gt;
         int vm = vl + (vr - vl) / 2;&lt;br /&gt;
         int ql = query(2 * v + 1, vl, vm, l, r);&lt;br /&gt;
         int qr = query(2 * v + 2, vm + 1, vr, l, r);&lt;br /&gt;
         return max(ql, qr);&lt;br /&gt;
     }&lt;br /&gt;
     void modify(int v, int vl, int vr, int pos, int val) {&lt;br /&gt;
         if (pos &amp;lt; vl || vr &amp;lt; pos)&lt;br /&gt;
             return;&lt;br /&gt;
         if (pos == vl &amp;amp;&amp;amp; vl == vr) {&lt;br /&gt;
             t[v] += val;&lt;br /&gt;
             return;&lt;br /&gt;
         }&lt;br /&gt;
         int vm = vl + (vr - vl) / 2;&lt;br /&gt;
         modify(2 * v + 1, vl, vm, pos, val);&lt;br /&gt;
         modify(2 * v + 2, vm + 1, vr, pos, val);&lt;br /&gt;
         t[v] = max(t[2 * v + 1], t[2 * v + 2]);&lt;br /&gt;
     }&lt;br /&gt;
 public:&lt;br /&gt;
     ST() {}&lt;br /&gt;
     ST(int n) {&lt;br /&gt;
         t = new int[4 * n];&lt;br /&gt;
         size = n;&lt;br /&gt;
         build(0, 0, size - 1);&lt;br /&gt;
     }&lt;br /&gt;
     int query(int l, int r) {&lt;br /&gt;
         return query(0, 0, size - 1, l, r);&lt;br /&gt;
     }&lt;br /&gt;
     void modify(int pos, int val) {&lt;br /&gt;
         modify(0, 0, size - 1, pos, val);&lt;br /&gt;
     }&lt;br /&gt;
 } st[100010];&lt;br /&gt;
&lt;br /&gt;
 int n, q, a, b;&lt;br /&gt;
 char c;&lt;br /&gt;
 vector&amp;lt;int&amp;gt; g[100010];&lt;br /&gt;
 int tIn[100010], tOut[100010], timer, size[100010], parent[100010];&lt;br /&gt;
 &lt;br /&gt;
 void dfs(int v) {&lt;br /&gt;
     tIn[v] = ++timer;&lt;br /&gt;
     size[v] = 1;&lt;br /&gt;
     for (int i = 0; i &amp;lt; g[v].size(); i++) {&lt;br /&gt;
         if (!tIn[g[v][i]]) {&lt;br /&gt;
             parent[g[v][i]] = v;&lt;br /&gt;
             dfs(g[v][i]);&lt;br /&gt;
             size[v] += size[g[v][i]];&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
     tOut[v] = ++timer;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 bool isAncestor(int a, int v) {&lt;br /&gt;
     return tIn[a] &amp;lt;= tIn[v] &amp;amp;&amp;amp; tOut[v] &amp;lt;= tOut[a];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 int chainInd[100010], chainPos[100010];&lt;br /&gt;
 int chainSize[100010], chainRoot[100010];&lt;br /&gt;
 int chainsCount;&lt;br /&gt;
 &lt;br /&gt;
 void buildHLD(int v, int chain) {&lt;br /&gt;
     chainInd[v] = chain;&lt;br /&gt;
     chainPos[v] = chainSize[chain];&lt;br /&gt;
     chainSize[chain]++;&lt;br /&gt;
     if (chainSize[chain] == 1)&lt;br /&gt;
         chainRoot[chain] = v;&lt;br /&gt;
     int maxChild = -1;&lt;br /&gt;
     for (int i = 0; i &amp;lt; g[v].size(); i++) {&lt;br /&gt;
         if (g[v][i] != parent[v] &amp;amp;&amp;amp; (maxChild == -1 || size[g[v][i]] &amp;gt; size[g[v][maxChild]]))&lt;br /&gt;
             maxChild = i;&lt;br /&gt;
     }&lt;br /&gt;
     if (maxChild != -1)&lt;br /&gt;
         &lt;br /&gt;
     for (int i = 0; i &amp;lt; g[v].size(); i++) {&lt;br /&gt;
         if (g[v][i] == parent[v])&lt;br /&gt;
             continue;&lt;br /&gt;
         if (i == maxChild)&lt;br /&gt;
             buildHLD(g[v][i], chain);&lt;br /&gt;
         else&lt;br /&gt;
             buildHLD(g[v][i], chainsCount++);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 int queryHLD(int a, int b) {&lt;br /&gt;
     int res = 0;&lt;br /&gt;
     while (1) {&lt;br /&gt;
         if (isAncestor(chainRoot[chainInd[a]], b))&lt;br /&gt;
             break;&lt;br /&gt;
         res = max(res, st[chainInd[a]].query(0, chainPos[a]));&lt;br /&gt;
         a = parent[chainRoot[chainInd[a]]];&lt;br /&gt;
     }&lt;br /&gt;
     while (1) {&lt;br /&gt;
         if (isAncestor(chainRoot[chainInd[b]], a))&lt;br /&gt;
             break;&lt;br /&gt;
         res = max(res, st[chainInd[b]].query(0, chainPos[b]));&lt;br /&gt;
         b = parent[chainRoot[chainInd[b]]];&lt;br /&gt;
     }&lt;br /&gt;
     if (chainPos[a] &amp;gt; chainPos[b])&lt;br /&gt;
         swap(a, b);&lt;br /&gt;
     return max(res, st[chainInd[a]].query(chainPos[a], chainPos[b]));&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 int main() {&lt;br /&gt;
     freopen(&amp;quot;input.txt&amp;quot;, &amp;quot;r&amp;quot;, stdin);&lt;br /&gt;
     freopen(&amp;quot;output.txt&amp;quot;, &amp;quot;w&amp;quot;, stdout);&lt;br /&gt;
 &lt;br /&gt;
     scanf(&amp;quot;%d&amp;quot;, &amp;amp;n);&lt;br /&gt;
     for (int i = 0; i &amp;lt; n - 1; i++) {&lt;br /&gt;
         scanf(&amp;quot;%d%d&amp;quot;, &amp;amp;a, &amp;amp;b);&lt;br /&gt;
         g[a - 1].push_back(b - 1);&lt;br /&gt;
         g[b - 1].push_back(a - 1);&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     dfs(0);&lt;br /&gt;
     buildHLD(0, chainsCount++);&lt;br /&gt;
     for (int i = 0; i &amp;lt; chainsCount; i++)&lt;br /&gt;
         st[i] = ST(chainSize[i]);&lt;br /&gt;
 &lt;br /&gt;
     scanf(&amp;quot;%d&amp;quot;, &amp;amp;q);&lt;br /&gt;
     for (int i = 0; i &amp;lt; q; i++) {&lt;br /&gt;
         scanf(&amp;quot; %c%d%d&amp;quot;, &amp;amp;c, &amp;amp;a, &amp;amp;b);&lt;br /&gt;
         if (c == &amp;#039;I&amp;#039;)&lt;br /&gt;
             st[chainInd[a - 1]].modify(chainPos[a - 1], b);&lt;br /&gt;
         else&lt;br /&gt;
             printf(&amp;quot;%d\n&amp;quot;, queryHLD(a - 1, b - 1));&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Ссылки на задачи ==&lt;br /&gt;
* [http://acm.timus.ru/problem.aspx?num=1553 Timus #1553 &amp;amp;mdash; Caves and Tunnels]&lt;br /&gt;
&lt;br /&gt;
== Ссылки ==&lt;br /&gt;
* [http://e-maxx.ru/algo/heavy_light e-maxx.ru &amp;amp;mdash; Heavy-light декомпозиция]&lt;br /&gt;
* [http://blog.anudeep2011.com/heavy-light-decomposition/ blog.anudeep2011.com &amp;amp;mdash; Heavy Light Decomposition]&lt;br /&gt;
* [http://github.com/indy256/codelibrary/blob/master/java/src/HeavyLight.java CodeLibrary &amp;amp;mdash; Heavy-light tree decomposition for edges or vertices]&lt;br /&gt;
* [http://github.com/ADJA/algos/blob/master/Graphs/HLD.cpp Algos &amp;amp;mdash; Heavy-light decomposition with segment trees in paths]&lt;br /&gt;
* [http://github.com/ADJA/algos/blob/master/Graphs/LCAHLD.cpp Algos &amp;amp;mdash; Finding LCA (Least common ancestor) of two vertices in the tree. Uses heavy-light decomposition]&lt;br /&gt;
&lt;br /&gt;
[[Категория:Учебный курс «Алгоритмы и структуры данных»]]&lt;/div&gt;</summary>
		<author><name>Ctrlalt</name></author>
	</entry>
</feed>