Discount On Crackers: Kharagpur Regionals

Here’s the link to the problem: CodeChef: Practical coding for everyone

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: qyZW2D - Online C++ Compiler & Debugging Tool - Ideone.com

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

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

Rest of your approach seems correct …

2 Likes

Brother, try this : IV6p3h - Online C++ Compiler & Debugging Tool - Ideone.com

1 Like

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?

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