File KTra LTDO
File KTra LTDO
{
int sodinh;
int start;
List<List<int>> dske;
try
{
using(StreamReader sr = new StreamReader("LienThongDFS.INP"))
{
String[] abc = sr.ReadLine().Split();
sodinh = int.Parse(abc[0]);
start = int.Parse(abc[1]);
dske = new List<List<int>>();
for(int i=0; i < sodinh; i++)
{
abc = sr.ReadLine().Split(new char[] { ' ' },
StringSplitOptions.RemoveEmptyEntries);
List<int> hang = new List<int>();
foreach(string s in abc)
{
hang.Add(int.Parse(s));
}
dske.Add(hang);
stack.Push(start);
luuvet[start - 1] = -1;
while(stack.Count != 0)
{
int dinhxet = stack.Pop();
foreach(int s in dske[dinhxet - 1])
{
if (luuvet[s - 1] == 0)
{
stack.Push(s);
luuvet[s - 1] =-1;
}
}
catch (FileNotFoundException)
{
Console.WriteLine("Khong Tim Thay File !");
}
int sodinh,start,end;
List<List<int>> dske;
int [] parent= new int[1000];
try
{
using (StreamReader sr = new StreamReader("TimDuongDFS.INP"))
{
String[] abc = sr.ReadLine().Split(new char[] { ' ' },
StringSplitOptions.RemoveEmptyEntries);
sodinh = int.Parse(abc[0]);
start = int.Parse(abc[1]);
end = int.Parse(abc[2]);
stack.Push(start);
luuvet[start - 1] = -1;
while (stack.Count != 0)
{
int dinhxet = stack.Pop();
if (duongdi.Count == 0)
{
Console.WriteLine("Khong co duong di tu dinh"+start+"den
dinh"+end);
sw.WriteLine(0);
}
else
{
Console.WriteLine(" Co duong di tu dinh " + start + " den
dinh " + end);
sw.WriteLine(duongdi.Count);
Console.WriteLine(duongdi.Count);
foreach(int dinh in duongdi)
{
Console.Write(dinh+" ");
sw.Write(dinh + " ");
}
}
}
}
}
catch (FileNotFoundException)
{
Console.WriteLine("Không Tìm Thấy File!");
}
}
}