Total nodes traversed in Euler Tour Tree | C ++ program to check the number of nodes in Euler Tour tree . ; Adjacency list representation of tree ; Function to add edges to tree ; Program to check if calculated Value is equal to 2 * size - 1 ; Add out - degree of each node ; Driver code ; Constructing 1 st tree from example ; Out_deg [ node [ i ] ] is equal to adj [ i ] . size ( ) ; clear previous stored tree ; Constructing 2 nd tree from example ; Out_deg [ node [ i ] ] is equal to adj [ i ] . size ( )
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define MAX  1001 NEW_LINE vector < int > adj [ MAX ] ; void add_edge ( int u , int v ) { adj [ u ] . push_back ( v ) ; } void checkTotalNumberofNodes ( int actualAnswer , int size ) { int calculatedAnswer = size ; for ( int i = 1 ; i <= size ; i ++ ) calculatedAnswer += adj [ i ] . size ( ) ; if ( actualAnswer == calculatedAnswer ) cout << " Calculated ▁ Answer ▁ is ▁ " << calculatedAnswer << " ▁ and ▁ is ▁ Equal ▁ to ▁ Actual ▁ Answer STRNEWLINE " ; else cout << " Calculated ▁ Answer ▁ is ▁ Incorrect STRNEWLINE " ; } int main ( ) { int N = 8 ; add_edge ( 1 , 2 ) ; add_edge ( 1 , 3 ) ; add_edge ( 2 , 4 ) ; add_edge ( 2 , 5 ) ; add_edge ( 3 , 6 ) ; add_edge ( 3 , 7 ) ; add_edge ( 6 , 8 ) ; checkTotalNumberofNodes ( 2 * N - 1 , N ) ; for ( int i = 1 ; i <= N ; i ++ ) adj [ i ] . clear ( ) ; N = 9 ; add_edge ( 1 , 2 ) ; add_edge ( 1 , 3 ) ; add_edge ( 2 , 4 ) ; add_edge ( 2 , 5 ) ; add_edge ( 2 , 6 ) ; add_edge ( 3 , 9 ) ; add_edge ( 5 , 7 ) ; add_edge ( 5 , 8 ) ; checkTotalNumberofNodes ( 2 * N - 1 , N ) ; return 0 ; }