WA IN SUBSGM

What is wrong with the following code 0UVmG0 - Online C++ Compiler & Debugging Tool - Ideone.com for the problem CodeChef: Practical coding for everyone.

As per the subtask 1 (i.e. 1 <= N <= 100, 1 <= M <= 1000) is considered, it should have passed. For rest, I know it would give TLE but why it is giving WA for subtask 1 also.

@damn_me: please ask your question on the problem editorial: Topics tagged ltime10