21 lines
531 B
C#
21 lines
531 B
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Assets.Map
|
|
{
|
|
public class Graph<T>
|
|
{
|
|
public List<T> Vertices { get; internal set; } = new List<T>();
|
|
public ISet<(int, int)> Edges { get; internal set; } = new HashSet<(int, int)>();
|
|
|
|
public void AddEdge(int a, int b)
|
|
{
|
|
Edges.Add(a < b ? (a, b) : (b, a));
|
|
}
|
|
|
|
public IEnumerable<(int, int)> EdgesOf(int a)
|
|
{
|
|
return Edges.Where(x => x.Item1 == a || x.Item2 == a);
|
|
}
|
|
}
|
|
} |