sorry, it&#39;s 15 seconds. It&#39;s a typo<br><br><div class="gmail_quote">On Wed, May 11, 2011 at 3:20 PM, Bin Jin <span dir="ltr">&lt;<a href="mailto:bjin1990@gmail.com">bjin1990@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi, cafe<br><br>I&#39;m recently solving some algorithm puzzles from previous Google Code Jam rounds, and today I met some problem I can&#39;t solve now.<br>It&#39;s a problem (Round 3 2010, B) that the solution require to find a shortest path in a graph with about 100,000 vertices <br>



and 50 edges from each vertex.  Apart from find shortest path, I find that building graph also takes a lot of time.<br>Yes, I know it&#39;s unnecessary to dump the entire graph to the memory, but I want to know if it&#39;s possible to build such graph in some reasonable time.<br>


<br>following is a snippet of code building the graph, runs about 15 mins on Core 2 Duo 2.40GHz without any RTS flags<br><br><blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex" class="gmail_quote">


&gt; <br>&gt; import Data.Array<br>&gt; <br>&gt; main = graph `seq` putStrLn &quot;Finished&quot;<br>&gt; <br>&gt; n = 100000<br>&gt; bnds = (0, n-1)<br>&gt; <br>&gt; buildGraph bnds edges = accumArray (flip (:)) [] bnds edges<br>


&gt; <br>&gt; graph = buildGraph bnds edges<br>&gt; <br>&gt; edges = [ (i, (y, 1 - x::Int))<br>&gt;         | i &lt;- range bnds<br>&gt;         , j &lt;- [2..50]<br>&gt;         , let (x, y) = if i + j &gt;= n then (1, i + j - n) else (0, i + j)<br>


&gt;         ]<br>&gt;<br></blockquote><br>Regards,<br><font color="#888888">Bin Jin<br>
</font></blockquote></div><br>