Professional Documents
Culture Documents
DFS
DFS
#include <algorithm>
using namespace std;
bool dd[1000]; //Mảng đánh dấu đỉnh ma trận
int dem=1, n;
int a[1000][1000]; //Ma trận đồ thị
int b[1000]; //Mảng để lưu thứ tự duyệt đồ thị
int main()
{
cout<<"nhap so dinh: "; cin>>n;
cout<<"Nhap ma tran do thi: \n";
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>a[i][j];
cout<<"Ma tran do thi: \n";
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<a[i][j]<<" "; cout<<endl;
}