function answer = digraph_arc_is_eulerian ( L )

%*****************************************************************************80
%
%% digraph_arc_is_eulerian() determines if a digraph is Eulerian.
%
%  Discussion:
%
%    A digraph is Eulerian if there exists a circuit through the graph
%    which uses every edge once.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    18 April 2026
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer node_num, the number of nodes.
%
%    integer edge_num, the number of edges.
%
%    integer L(edge_num,2), the edge list.
%
%  Output:
%
%    integer answer.
%    0, the digraph is not Eulerian.
%    1, the digraph is Eulerian, but the starting and ending nodes differ.
%    2, the digraph is Eulerian, and there is a closed Euler circuit.
%
  node_num = max ( max ( L ) );

  [ indegree, outdegree ] = digraph_arc_degree ( L );

  n_plus = 0;
  n_minus = 0;

  for i = 1 : node_num

    if ( indegree(i) == outdegree(i) )

    elseif ( n_plus == 0 && indegree(i) == outdegree(i) + 1 )
      n_plus = 1;
    elseif ( n_minus == 0 && indegree(i) == outdegree(i) - 1 )
      n_minus = 1;
    else
      answer = 0;
      return
    end

  end

  if ( n_plus == 0 && n_minus == 0 )
    answer = 2;
  else if ( n_plus == 1 && n_minus == 1 )
    answer = 1;
  else
    fprintf ( 1, '\n' );
    fprintf ( 1, 'digraph_arc_is_eulerian(): Fatal error!\n' );
    fprintf ( 1, '  The algorithm failed.\n' );
    error ( 'digraph_arc_is_eulerian(): Fatal error!' );
  end

  return
end
