Using namespace std
Download 16.5 Kb.
|
1 chi
masalalarni yechishda odatda har bir yoy ma'lum vazn (og'irlik)ga (yoki uzunlikga) egabo'lgan vazn graflar(Weighted graph) qo'llaniladi.Bunday graflar tarmoq(to'r) deb ataladi. Graflarni tavsiflash uchun odatda ikkita turdagi matritsalar qo'llaniladi-qo'shnilik matrisasi(vaznga ega bo'lmagan graflar uchun) va vaznli matritsa (vaznli graflar uchun). N ta tugun grafning qo'shnilik matritsasi(adjacency matrix)-bu N ga N o'lchamli matritsa hisoblanib uning har bir (i,j) indeksli elementi i tugundan j tugunga yoy mavjud yokimavjud emasligini ko'rsatuvchi mantiqiy qiymatlardan iborat bo'ladi. #include using namespace std; int main() { int o'zgarmas, kk=100000, v,t, c[100][100],n; cout«"matritsa o'lchamini - "«endl; cin»n;
cout«"c[i][j] "«endl; for(int i=0; i for(int j=0; j cin»c[i][j]; t=0; o'zgarmas=0; v=0;
cout«"1 ->"; for(int k=0; k { for(int i=0; i if(c[v][i] cout«t+1«"->"; cost+=c[v][t];
for(int i=0; i c[i][t]=0;
if(k!=(n-2)) c[t][0]=0; v=t;
kk=10000000; cout«"1"«endl; o'zgarmas+=c[v][0];
return 0; }
2-masala: #include using namespace std;
int main() { queue int mas[10][10]; int mirjalol[10];
int i,j,n; cin»n; for(i=0;i for(j=0;j cin»mas[i][j];
for (int i = 0; i < n; i++) mirjalol[i] = 0;
Queue.push(0); while (!Queue.empty())
{
int sr = Queue.front(); mirjalol[sr] = 2; for (int j = 0; j < n; j++)
{
if (mas[sr][j] == 1 && mirjalol[j] == 0) Queue.push(j); mirjalol[j] = 1;
}}
|
ma'muriyatiga murojaat qiling