I am very sorry that I made some mistakes when I tried to solve the problem. The PR proposed a valid approach in fact. Now, I have successfully solved the problem. Thanks!