C:\Users\DELL\Desktop\CP\CodeChef\FIRESC.cpp: In function 'void initialise()':
C:\Users\DELL\Desktop\CP\CodeChef\FIRESC.cpp:10:8: error: 'i' was not declared in this scope
adj[i].clear();
^
C:\Users\DELL\Desktop\CP\CodeChef\FIRESC.cpp: At global scope:
Someone please help me in two things :
a) How to find the number of ways to choose a captain?
b) What is the error in my half-finished code?
just see how many people are there in each group, and then by basic PnC principle of multiplication, you might be knowing that if say there are 3 people in group A, 2 in group B and 6 in group C , then total no. of ways of selecting 1 person from each group is (3X2X6) that is 36 ways
When you apply dfs for all the nodes, and after traversing each connected component you come back to the loop in main function, you can keep a counter variable that tells how many times dfs is called for each node in a single connected component. And before continuing the loop for further nodes you can store that counter maybe in some array if you like ā¦ and then reinitialize the counter variable to 0 .