Determine number of connected components
Ruby, 77 characters
gets;0while$_.sub!(/\b(\d+)\b(.*) (\1-\d+|\d+-\1)\b/,'\3\2');p$_.count(&quot; &quot;)+1

A first plain attempt in Ruby. It collects the sub-graphs using a regular expression until no more connections can be made.
Examples:
&gt; 1-2 2-3 3-4 4-1
1

&gt; 1-2 2-3 4-5
2

&gt; 1-2 3-4 8-9 1-6 5-7 7-4 10-9
3