static void Bai_01()
{
int sodinh;
int start;
List<List<int>> dske;
try
{
using(StreamReader sr = new StreamReader("[Link]"))
{
String[] abc = [Link]().Split();
sodinh = [Link](abc[0]);
start = [Link](abc[1]);
dske = new List<List<int>>();
for(int i=0; i < sodinh; i++)
{
abc = [Link]().Split(new char[] { ' ' },
[Link]);
List<int> hang = new List<int>();
foreach(string s in abc)
{
[Link]([Link](s));
}
[Link](hang);
//Thuat Toan xu ly' DFS
Stack<int> stack = new Stack<int>();
int[] luuvet = new int[sodinh];
[Link](start);
luuvet[start - 1] = -1;
while([Link] != 0)
{
int dinhxet = [Link]();
foreach(int s in dske[dinhxet - 1])
{
if (luuvet[s - 1] == 0)
{
[Link](s);
luuvet[s - 1] =-1;
}
}
//xac dinh cac dinh lien thong voi star
List<int> dinhlienthong = new List<int>();
for (int dinh = 1; dinh <= sodinh; dinh++)
{
if (luuvet[dinh - 1] != 0 && dinh != start)
{
[Link](dinh);
}
}
[Link]([Link]);
//In ra
foreach (int s in dinhlienthong)
{
[Link]( s+" ");
}
catch (FileNotFoundException)
{
[Link]("Khong Tim Thay File !");
}
static void Bai_02()
{
int sodinh,start,end;
List<List<int>> dske;
int [] parent= new int[1000];
try
{
using (StreamReader sr = new StreamReader("[Link]"))
{
String[] abc = [Link]().Split(new char[] { ' ' },
[Link]);
sodinh = [Link](abc[0]);
start = [Link](abc[1]);
end = [Link](abc[2]);
dske = new List<List<int>>();
for (int i = 0; i < sodinh; i++)
{
abc = [Link]().Split(new char[] { ' ' });
List<int> hang = new List<int>();
foreach (string s in abc)
{
[Link]([Link](s));
}
[Link](hang);
}
// Thuật toán xử lý DFS
Stack<int> stack = new Stack<int>();
int[] luuvet = new int[sodinh];
[Link](start);
luuvet[start - 1] = -1;
while ([Link] != 0)
{
int dinhxet = [Link]();
foreach (int dinhke in dske[dinhxet - 1])
{
if (luuvet[dinhke - 1] == 0)
{
[Link](dinhke);
luuvet[dinhke - 1] = dinhxet;
}
}
}
// Xác định các đỉnh liên thông với start
List<int> duongdi = new List<int>();
if (luuvet[end - 1] != 0)
{
for(int i= end; i != -1; i = luuvet[i - 1])
{
[Link](i);
}
[Link]();
}
// Ghi kết quả ra file output
using (StreamWriter sw = new StreamWriter("[Link]"))
{
if ([Link] == 0)
{
[Link]("Khong co duong di tu dinh"+start+"den
dinh"+end);
[Link](0);
}
else
{
[Link](" Co duong di tu dinh " + start + " den
dinh " + end);
[Link]([Link]);
[Link]([Link]);
foreach(int dinh in duongdi)
{
[Link](dinh+" ");
[Link](dinh + " ");
}
}
}
}
}
catch (FileNotFoundException)
{
[Link]("Không Tìm Thấy File!");
}
}
}