With the US election going on right now, I noticed that there is one (completely meaningless, but still) thing which Trump can still achieve and which is out of reach for Biden: Having the won states being connected.
Task: Given a list of strings of two-letter abbreviations (see below) for US states, determine whether they are connected. That is, is the graph whose edges are the states in this list and where two edges are connected whenever the corresponding states are neighbors to each other connected? That is, for each two states, does there exist a path (in this graph) from one to another?
AK,WA AL,FL AL,GA AL,MS AL,TN AR,LA AR,MO AR,MS AR,OK AR,TN AR,TX AZ,CA AZ,CO AZ,NM AZ,NV AZ,UT CA,HI CA,NV CA,OR CO,KS CO,NE CO,NM CO,OK CO,UT CO,WY CT,MA CT,NY CT,RI DC,MD DC,VA DE,MD DE,NJ DE,PA FL,GA GA,NC GA,SC GA,TN IA,IL IA,MN IA,MO IA,NE IA,SD IA,WI ID,MT ID,NV ID,OR ID,UT ID,WA ID,WY IL,IN IL,KY IL,MO IL,WI IN,KY IN,MI IN,OH KS,MO KS,NE KS,OK KY,MO KY,OH KY,TN KY,VA KY,WV LA,MS LA,TX MA,NH MA,NY MA,RI MA,VT MD,PA MD,VA MD,WV ME,NH MI,OH MI,WI MN,ND MN,SD MN,WI MO,NE MO,OK MO,TN MS,TN MT,ND MT,SD MT,WY NC,SC NC,TN NC,VA ND,SD NE,SD NE,WY NH,VT NJ,NY NJ,PA NM,OK NM,TX NM,UT NV,OR NV,UT NY,PA NY,VT OH,PA OH,WV OK,TX OR,WA PA,WV SD,WY TN,VA UT,WY VA,WV
To be clear, “to be a neighbor of” is symmetric and hence the entry
AK,WA means that AK neighbors WA and that WA neighbors AK. There might be some disagreement whether some of these states are indeed neighbors of each other but for the purpose of this question, let us go with the list above. (Although that would mean that Trump needs to lose Alaska in order to have his won states connected.)
Input: A list of two-letter strings or something equivalent such as a single string consisting of a series of two-letter pairs such as
"AK WA OR" or
"AKWAOR". It may be assumed that each string is one of the two-letter abbreviations in the list above and that no string appears more than once in the list.
Output: Return/Ouput a truthy value if the states are connected and a falsey value if they are not.
(Very!) simple test cases:
["AK", "WA", "OR"]is connected.
["UT", "CO", "WY", "KS", "NM"]is connected. (That is, they form a connected graph although they do not form a “line” of neighboring states.)
["AK", "OR"]is not connected.
["ID", "OR", "WA", "AL", "GA", "TN"]is not connected.
This is code-golf, so shortest code in bytes wins.