Help for FIRESC

I was solving FIRESC

My half finished code :

Also, my half-finished code gives the error :

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 
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?

for (int i = 0; i < 100001; i++){}

Remove the } from the end of the line.

Decide between addEdges or addEdge and stick to it.


And everything else XD


Yeah I found that out, was a silly typo. How to find the number of ways to select a captain?

No idea :man_shrugging: :slight_smile:

1 Like

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

Yeah that is equivalent to finding the number of nodes in each connected component. How do I count the number of nodes in each connected component?

I have plans to create a global array called int count[1000001] and then insert a new line here :

void dfs(int v){
int count = 0;
vis[v] = 1;
for (auto child : adj[v]){
if (!vis[child]){

But my only doubt is : How do I store these count variables and then multiply them?

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 .

Iā€™m really unable to visualise it. Can someone please code it and send it?
My code :

My Code

The problems is simply: Given a graph G, find number of nodes in each of connected components and print their product modulo M.