According to the 1327B's solution, O(n+m) is taken.
But i don't think that. In this situation,
N = 100'000 1st princess can marry 1 2 3 4 ... 100'000 2nd princess can marry 1 2 3 4 .., 100'000 . . . 100'000th princess can marry 1 2 3 4 .. 100'000
Total time complexity will be O(N^2), if i understood that solution correct.
Can you help me?