<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tarjan Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/tarjan/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/tarjan/</link>
	<description></description>
	<lastBuildDate>Tue, 17 Sep 2019 04:37:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>tarjan Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/tarjan/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1192. Critical Connections in a Network</title>
		<link>https://zxi.mytechroad.com/blog/graph/leetcode-1192-critical-connections-in-a-network/</link>
					<comments>https://zxi.mytechroad.com/blog/graph/leetcode-1192-critical-connections-in-a-network/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 15 Sep 2019 23:07:27 +0000</pubDate>
				<category><![CDATA[Graph]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[hard]]></category>
		<category><![CDATA[O(V+E)]]></category>
		<category><![CDATA[tarjan]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5556</guid>

					<description><![CDATA[<p>There are&#160;n&#160;servers numbered from&#160;0&#160;to&#160;n-1&#160;connected by&#160;undirected server-to-server&#160;connections&#160;forming a network where&#160;connections[i] = [a, b]&#160;represents a connection between servers&#160;a&#160;and&#160;b. Any server can reach any other server directly or&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/graph/leetcode-1192-critical-connections-in-a-network/">花花酱 LeetCode 1192. Critical Connections in a Network</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>There are&nbsp;<code>n</code>&nbsp;servers numbered from&nbsp;<code>0</code>&nbsp;to&nbsp;<code>n-1</code>&nbsp;connected by&nbsp;undirected server-to-server&nbsp;<code>connections</code>&nbsp;forming a network where&nbsp;<code>connections[i] = [a, b]</code>&nbsp;represents a connection between servers&nbsp;<code>a</code>&nbsp;and&nbsp;<code>b</code>. Any server can reach any other server directly or indirectly through the network.</p>



<p>A&nbsp;<em>critical connection</em>&nbsp;is a connection that, if removed, will make some server unable to reach some other server.</p>



<p>Return all critical connections in the network in any order.</p>



<p><strong>Example 1:</strong></p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2019/09/03/1537_ex1_2.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> n = 4, connections = [[0,1],[1,2],[2,0],[1,3]]
<strong>Output:</strong> [[1,3]]
<strong>Explanation:</strong> [[3,1]] is also accepted.
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= n &lt;= 10^5</code></li><li><code>n-1 &lt;= connections.length &lt;= 10^5</code></li><li><code>connections[i][0] != connections[i][1]</code></li><li>There are no repeated connections.</li></ul>



<h2><strong>Solution: Tarjan</strong></h2>



<p>Time complexity: O(v+e)<br>Space complexity: O(v+e)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;vector&lt;int&gt;&gt; criticalConnections(int n, vector&lt;vector&lt;int&gt;&gt;&amp; connections) {
    vector&lt;vector&lt;int&gt;&gt; g(n);
    vector&lt;int&gt; ts(n, INT_MAX);
    vector&lt;vector&lt;int&gt;&gt; ans;
    int t = 0;
    
    function&lt;int(int, int)&gt; tarjan = [&amp;](int i, int p) {
      int min_i = ts[i] = ++t;
      for (int j : g[i]) {
        if (ts[j] == INT_MAX) {
          int min_j = tarjan(j, i);
          min_i = min(min_i, min_j);
          if (ts[i] &lt; min_j)
            ans.push_back({i, j});
        } else if (j != p) {
          min_i = min(min_i, ts[j]);
        }
      }
      return min_i;
    };
    
    for (const auto&amp; e : connections) {
      g[e[0]].push_back(e[1]);
      g[e[1]].push_back(e[0]);
    }
    
    tarjan(0, -1);
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/graph/leetcode-1192-critical-connections-in-a-network/">花花酱 LeetCode 1192. Critical Connections in a Network</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/graph/leetcode-1192-critical-connections-in-a-network/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
