using
System;
using
System.Collections.Generic;
class
GFG {
static
string
SimilarGame(
string
[, ] arr)
{
Dictionary<
string
,
int
> indegree
=
new
Dictionary<
string
,
int
>();
Dictionary<
string
,
int
> outdegree
=
new
Dictionary<
string
,
int
>();
SortedSet<
string
> st =
new
SortedSet<
string
>();
for
(
int
i = 0; i < arr.GetLength(0); i++) {
if
(arr[i, 0] == arr[i, 1])
return
"No"
;
st.Add(arr[i, 0]);
st.Add(arr[i, 1]);
if
(outdegree.ContainsKey(arr[i, 0])) {
outdegree[arr[i, 0]]++;
}
else
outdegree.Add(arr[i, 0], 1);
if
(indegree.ContainsKey(arr[i, 0])) {
indegree[arr[i, 0]]++;
}
else
indegree.Add(arr[i, 0], 1);
}
if
(outdegree.Count != 3 || indegree.Count != 3
|| st.Count != 3)
return
"No"
;
foreach
(KeyValuePair<
string
,
int
> it
in
outdegree)
{
if
(it.Value != 1)
return
"No"
;
}
foreach
(KeyValuePair<
string
,
int
> it
in
indegree)
{
if
(it.Value != 1)
return
"No"
;
}
return
"Yes"
;
}
public
static
void
Main(
string
[] args)
{
string
[, ] arr = { {
"Snake"
,
"Water"
},
{
"Water"
,
"Gun"
},
{
"Gun"
,
"Snake"
} };
Console.WriteLine(SimilarGame(arr));
}
}