Prison Break solution codeforces
Prison Break solution codeforces
Michael is accused of violating the social distancing rules and creating a risk of spreading coronavirus. He is now sent to prison. Luckily, Michael knows exactly what the prison looks like from the inside, especially since it’s very simple.
The prison can be represented as a rectangle a×ba×b which is divided into abab cells, each representing a prison cell, common sides being the walls between cells, and sides on the perimeter being the walls leading to freedom. Before sentencing, Michael can ask his friends among the prison employees to make (very well hidden) holes in some of the walls (including walls between cells and the outermost walls). Michael wants to be able to get out of the prison after this, no matter which cell he is placed in. However, he also wants to break as few walls as possible.
Your task is to find out the smallest number of walls to be broken so that there is a path to the outside from every cell after this.
Input Prison Break solution codeforcesThe first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases.
Each of the following tt lines contains two integers aa and bb (1≤a,b≤1001≤a,b≤100), representing a corresponding test case.
Output Prison Break solution codeforcesFor each test case print the single integer on a separate line — the answer to the problem.
ExampleinputCopy22213output Prison Break solution codeforcesCopy 43NoteSome possible escape plans for the example test cases are shown below. Broken walls are shown in gray, not broken walls are shown in black.


Michael is accused of violating the social distancing rules and creating a risk of spreading coronavirus. He is now sent to prison. Luckily, Michael knows exactly what the prison looks like from the inside, especially since it’s very simple.
The prison can be represented as a rectangle a×ba×b which is divided into abab cells, each representing a prison cell, common sides being the walls between cells, and sides on the perimeter being the walls leading to freedom. Before sentencing, Michael can ask his friends among the prison employees to make (very well hidden) holes in some of the walls (including walls between cells and the outermost walls). Michael wants to be able to get out of the prison after this, no matter which cell he is placed in. However, he also wants to break as few walls as possible.
Your task is to find out the smallest number of walls to be broken so that there is a path to the outside from every cell after this.
The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases.
Each of the following tt lines contains two integers aa and bb (1≤a,b≤1001≤a,b≤100), representing a corresponding test case.
For each test case print the single integer on a separate line — the answer to the problem.
Some possible escape plans for the example test cases are shown below. Broken walls are shown in gray, not broken walls are shown in black.


SOLUTION
” COMING SOON “
------------------------------------------------END----------------------------------------------------------------------
Social Plugin