Count the nodes of the tree which make a pangram when concatenated with the sub | C # implementation of the above approach ; Function that returns if the String x is a pangram ; Function to return the count of nodes which make pangram with the sub - tree nodes ; Function to perform dfs and update the nodes such that weight [ i ] will store the weight [ i ] concatenated with the weights of all the nodes in the sub - tree ; Driver code ; Weights of the nodes ; Edges of the tree
using System ; using System . Collections . Generic ; class GFG { static List < int > [ ] graph = new List < int > [ 100 ] ; static String [ ] weight = new String [ 100 ] ; static bool Pangram ( String x ) { Dictionary < char , int > mp = new Dictionary < char , int > ( ) ; int n = x . Length ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( x [ i ] ) ) { mp [ x [ i ] ] = mp [ x [ i ] ] + 1 ; } else { mp . Add ( x [ i ] , 1 ) ; } } if ( mp . Count == 26 ) return true ; else return false ; } static int countTotalPangram ( int n ) { int cnt = 0 ; for ( int i = 1 ; i <= n ; i ++ ) if ( Pangram ( weight [ i ] ) ) cnt ++ ; return cnt ; } static void dfs ( int node , int parent ) { foreach ( int to in graph [ node ] ) { if ( to == parent ) continue ; dfs ( to , node ) ; weight [ node ] += weight [ to ] ; } } public static void Main ( String [ ] args ) { int n = 6 ; weight [ 1 ] = " abcde " ; weight [ 2 ] = " fghijkl " ; weight [ 3 ] = " abcdefg " ; weight [ 4 ] = " mnopqr " ; weight [ 5 ] = " stuvwxy " ; weight [ 6 ] = " zabcdef " ; for ( int i = 0 ; i < graph . Length ; i ++ ) graph [ i ] = new List < int > ( ) ; graph [ 1 ] . Add ( 2 ) ; graph [ 2 ] . Add ( 3 ) ; graph [ 2 ] . Add ( 4 ) ; graph [ 1 ] . Add ( 5 ) ; graph [ 5 ] . Add ( 6 ) ; dfs ( 1 , 1 ) ; Console . Write ( countTotalPangram ( n ) ) ; } }