Find if possible to visit every nodes in given Graph exactly once based on given conditions | C # program for above approach . ; Function to find print path ; If a [ 0 ] is 1 ; Printing path ; Seeking for a [ i ] = 0 and a [ i + 1 ] = 1 ; Printing path ; If a [ N - 1 ] = 0 ; Driver Code ; Given Input ; Function Call
using System ; class GFG { static void findpath ( int N , int [ ] a ) { if ( a [ 0 ] != 0 ) { Console . Write ( N + 1 ) ; for ( int i = 1 ; i <= N ; i ++ ) Console . Write ( i + " ▁ " ) ; return ; } for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( a [ i ] == 0 && a [ i + 1 ] != 0 ) { for ( int j = 1 ; j <= i ; j ++ ) Console . Write ( j + " ▁ " ) ; Console . Write ( N + 1 + " ▁ " ) ; for ( int j = i + 1 ; j <= N ; j ++ ) Console . Write ( j + " ▁ " ) ; return ; } } for ( int i = 1 ; i <= N ; i ++ ) Console . Write ( i + " ▁ " ) ; Console . Write ( N + 1 + " ▁ " ) ; } public static void Main ( ) { int N = 3 ; int [ ] arr = { 0 , 1 , 0 } ; findpath ( N , arr ) ; } }