Using namespace std


Download 16.5 Kb.
Sana06.12.2021
Hajmi16.5 Kb.
#178839
Bog'liq
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

#include

using namespace std;

int main()

{ queue 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();



Queue.pop();

mirjalol[sr] = 2;

for (int j = 0; j < n; j++)

{

if (mas[sr][j] == 1 && mirjalol[j] == 0)



{

Queue.push(j);

mirjalol[j] = 1;

}}

cout «sr + 1 « endl;



} cin.get();

return 0;}

Download 16.5 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling