g | x | w | all
Bytes Lang Time Link
132Python 3240830T025537ZLucenapo
066JavaScript Node.js240830T021439Zl4m2
213Python3240830T003510ZAjax1234
020SageMath230415T064438Z138 Aspe
017Vyxal230313T055946Zlesobrod
068JavaScript ES6230309T213116ZArnauld
056Arturo230310T000201Zchunes
01005AB1E230310T045013ZCommand
033Charcoal230309T230625ZNeil
022Wolfram Language Mathematica230309T190742ZZaMoC

Python 3, 132 bytes

def f(a,b):N=len(a);a=sum(a,[]);b=sum(b,[]);p=[1];g=lambda x,y:x[1^x.index(y)];exec('p+=g(%c,p[-1]),;'*2%(97,98)*N);1<<len({*p})-N-N

Try it online!

If it forms a loop, no error. Otherwise error

JavaScript (Node.js), 66 bytes

f=(x,i=k=0)=>!x[k++]|x.some(([a,b],j)=>a==i|b==i&&f(x[j]=x,a^b^i))

Try it online!

Start from 0, go through all nodes(x[j]=x cuts the edge), and decide if it went through N edges

Python3, 213 bytes

def f(t,b):
 d={}
 for a,b in t+b:d[a]=d.get(a,[])+[b];d[b]=d.get(b,[])+[a]
 q,s=[(k:=[*d][0],[k])],0
 for a,b in q:
  for j in d[a]:
   if j in b:s=s or all(i in b for i in d);continue
   q+=[(j,b+[j])]
 return s

Try it online!

SageMath, 20 bytes

Run it on SageMathCell!

g=Graph.is_connected

Vyxal, 17 bytes A

vṅ÷:Ld1$(voÞṡḣ‟)₃

Input: nested array, output: 1(True), 0(False)

vṅ                  # Convert all pairs to strings
  ÷:L               # Split and find length of one list
     d              # Double length (get number of straws N)
      1$            # Push 1 (may be any straw number 1..N) and swap
        (           # Begin "for" loop N times
         vo         # Remove index of current straw
            Þṡ      # Sort by length
              ḣ‟    # Extract head (next index) and rotate
                )₃  # End loop and compare length with 1

Try it Online!

JavaScript (ES6), 68 bytes

Expects (N)(list), where list contains all 0-indexed pairs. Returns \$0\$ or \$1\$.

(n,m=1)=>g=a=>a.some(([x,y,q=1<<x|1<<y])=>m&q&&m^(m|=q))?g(a):m+1>>n

Try it online!

Commented

(              // outer function taking:
  n,           //   n = number of straws
  m = 1        //   m = bit mask, initialized to 1
) =>           //
g = a =>       // inner recursive function taking the array of links a[]
a.some(([      // for each link
  x, y,        // with x, y = straw indices
  q = 1 << x | // and q = corresponding bit mask for these indices:
      1 << y   //
]) =>          //
  m & q &&     //   if m and q have at least one bit in common:
    m ^        //     test whether m is changed when
    (m |= q)   //     the bits of q are merged with those of m
)              // end of some()
?              // if truthy:
  g(a)         //   do a recursive call
:              // else:
  m + 1 >> n   //   return 1 if the n least significant bits of m are set

65 bytes

Same input format, but returns \$1\$ for true and some integer \$>1\$ for false.

(n,m=1)=>g=a=>a.some(([x,y,q=1<<x|1<<y])=>m&q&&m^(m|=q))?g(a)-1:n

Try it online!

Arturo, 58 56 bytes

$[a,b,n][∨∧n=2a<>b every? a'x->every? b=>[[]<>--x&]]

Try it

$[a,b,n][               ; a function taking three arguments
    ∨∧n=2a<>b           ; is n equal to 2 and a not equal to b? or is...
    every? a'x->        ; every pair from a
        every? b=>[     ; paired with every pair from b
            []<>--x&    ; not empty when their set difference is taken?
        ]               ; end every
]                       ; end function

05AB1E, 10 bytes

æʒ˜D¢ÈP}g<

Try it online!

Takes as input a list of pairs such that two straws have the same first element if they are connected at the top, and the same second element if they are connected at the bottom. Requires the top and bottom values to be disjoint. Can take them as two separate lists at a cost of +1 byte.

Returns an 05AB1E boolean, which is 1 for true and any other value for false. Can be made to return a 1 or 0 by adding Θ (05AB1E truthified) at the end.

Explanation

We return the number of subsets of straws which aren't connected to any straw not in the subset minus one. Those subsets are the ones which can be partitioned to cycles. If there is a single cycle, the only such subsets will be the entire set and the empty set, and we will return 1. However, if there are any more cycles, there will be more than 2 such sets (for example - the empty set, all the straws, and the straws in any cycle), so we will return a number greater than 1 which is falsey in 05AB1E

æ     for all subsets of straws
ʒ     only keep those such that:
 ˜     after flattening the pairs
 D     if we duplicate the list
 ¢     and count the number of occurrences of each value
 È     and check that it's even
 P     the product will be 1 - that is, all values appear an even number of times
}
g     count how many such sets are there
<     decrease it by 1 (and implicitly output)

Charcoal, 33 bytes

F§θ⁰⊞υιWΦE⁺θη⁻κυ⁼¹LκFι⊞υ⊟κ⊙⁺θη⁻ιυ

Try it online! Link is to verbose version of code. Outputs an inverted Charcoal boolean, i.e. nothing if the straws are linked, - if they are not. Explanation:

F§θ⁰⊞υι

Make a copy of the first link.

WΦE⁺θη⁻κυ⁼¹Lκ

While links between previously linked straws and as yet unlinked straws exist...

Fι⊞υ⊟κ

... push all newly linked straws to the list.

⊙⁺θη⁻ιυ

Check whether any unlinked straws remain.

Note that the input format guarantees that if the straws are all linked then they will be in a single cycle.

Wolfram Language (Mathematica), 22 bytes

ConnectedGraphQ@*Graph

Try it online!