Why is this code Seg_Faulting?
<p>I can't understand why this code would segmentation fault. Any help out there? This is for a riddle in a book, not for a homework assignment. </p>

<p>Code : <a href="http://pastebin.com/WvWkckzX" rel="nofollow">http://pastebin.com/WvWkckzX</a></p>

<p>Input : <a href="http://pastebin.com/yvHXquuf" rel="nofollow">http://pastebin.com/yvHXquuf</a></p>

<p>Prompt : <a href="http://pastebin.com/dmmyG2DY" rel="nofollow">http://pastebin.com/dmmyG2DY</a></p>

<p>Input:
The first line contains the number of test cases T. T test cases follow. The first line of each test case contains N and M. The next N lines describe the cities in Byteland. The ith line contains a letter 'A' or 'B' signifying the army division located in city i and the cost ci of defeating that army. The next M lines describe the roads in the city. The ith line contains xi and yi, the numbers of the cities connected by a road.</p>

<p>Output:
Output T lines, one corresponding to each test case containing the cheapest cost of accomplishing your goal.</p>

<p>Sample Input:</p>

<pre><code>1
3 3
A 1
A 1
B 10
1 2
1 3
2 3
</code></pre>

<p>Sample Output:</p>

<pre><code>2
</code></pre>

<p>City 1 (A-1) connects to city 2 (A-1) and city 3 (B-10). To attack city 3 will cost 10, while to simply attack cities 1 and 2 will cost only 2.</p>

<p>GDB tells me that it seg faults in 'cost_testCase'</p>
