Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-047

Eulerian Circuit Existence

Problem

Decide whether an undirected graph with n nodes has an Eulerian circuit: a closed trail that visits every edge exactly once.

edges is a list of [u, v] pairs. All nodes with nonzero degree must form one connected component and every degree must be even.

Hint

An Eulerian circuit needs every degree even and all edges in one component.

Test cases

case 1
in: [3,[[0,1],[1,2],[2,0]]]
expected: true
case 2
in: [3,[[0,1],[1,2]]]
expected: false
case 3
in: [6,[[0,1],[1,2],[2,0],[3,4],[4,5],[5,3]]]
expected: false
case 4
in: [1,[]]
expected: true
case 5
in: [4,[[0,1],[1,2],[2,3],[3,0],[0,2]]]
expected: false
Starter codePython
def has_eulerian_circuit(n, edges):
    # Your code here
    pass

5 test cases · run your code against them in the editor