Discount On Crackers: Kharagpur Regionals

Here’s the link to the problem:

I have built a graph having nodes a-z. and mapped each rule (a->b, b->c, etc) as edges of the graph.

Go through each character of both strings( say, character a and b) and check if both nodes a and b are connected using a depth-first-search.

I have got a lot of wrong answers during the contest. It might be due to few edge cases which I could miss or my approach could have been outright wrong.

Please help me figure it out.

Here’s my code:

i solved it using floyd warshall… cant see your code…but a question…are you taking care of this case
// modifications

as all the modifications will be useless and modifications won’t provide a->a…

Rest of your approach seems correct …


Thanks for the reply.
I have checked the case which you have provided. It works. There might be some test case for which my approach fails. Is there any way by which I could find it out?

Brother, try this :

1 Like

Thanks bro. But I wanted to know the fault in my approach. :frowning: