Professional Documents
Culture Documents
22DH110457 BT9
22DH110457 BT9
static void ReadEdgeList(string path, out int n, out int m, out List<Tuple<int, int,int>> edgeList)
{
StreamReader sr = new StreamReader(path);
string line = sr.ReadLine();
string[] values = line.Split();
n = Convert.ToInt32(values[0]);
m = Convert.ToInt32(values[1]);
edgeList = new List<Tuple<int, int, int>>();
static void ConvertEdgeList2AdjList(int n, int m, List<Tuple<int, int, int>> edgeList, out List<Tuple<int, int>>[]
adjList)
{
adjList = new List<Tuple<int, int>>[n];
Initialize();
SpanningTree(0);
}
public static void SpanningTree(int s)
{
visited[s] = true;
TreeDFS(s);
PrintSpanningTree();
}
static void Initialize()
{
visited = new bool[n];
for (int i = 0; i < visited.Length; i++)
{
visited[i] = false;
}
}
int v = edge.Item1;
int u = edge.Item2;
if (!IsConnected(v, u))
{
tree.Add(edge);
Union(v, u);
}
}
ShowTree();
}
BÀI 3: PRIM
using System;
using System.Collections.Generic;
public Graph(int v)
{
n = v;
g = new List<Tuple<int, int, int>>();
label = new bool[n + 1];
tree = new List<Tuple<int, int, int>>();
}
ShowTree();
}
return emin;
}