1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
using namespace std;


int main()
{
	short n,k,l;
	int koszt=0;
	short wsp1,wsp2;
	cin >> n;
	k=n;
	int **c = new int *[n];
	

	k=n-1;
	while (k>=0)
	{
		for(short i=0; i<n; i++)
		{
			c[i]= new int[k+1];
			for(short j=0; j<=k; j++)
			{
				cin >> c[i][j];
			}
		k--;
		}
	}
	int min;
	min=c[0][0];
	for (short i=1; i<n; i++)
	{
		if(min>=c[i][0])
		{
			min=c[i][0];
			wsp1=i;
		}
	}
	k=n;
	koszt=min;
	cout << min << endl;
	c[wsp1][0]=1000000000;
	min=1000000000;
	l=k-2;
		for(short i=1; i<n; i++)
		{
			for(short j=0; j<=l; j++)
			{
				if (min>=c[i][j])
				{
					min=c[i][j];
					wsp1=i;
					wsp2=j;
				}
				if(min>=c[j][i])
				{
						min=c[j][i];
						wsp1=j;
						wsp2=i;
				}
				
			}
			l--;
			cout << min << endl;
			koszt=koszt+min;
			c[wsp1][wsp2]=1000000000;
			min=1000000000;
			
		}
	cout << koszt;
	
}