CF1484A.Prison Break

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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\times 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 ( 1t1001\leq t\leq 100 ) — the number of test cases.

Each of the following tt lines contains two integers aa and bb ( 1a,b1001\leq a, b\leq 100 ), representing a corresponding test case.

输出格式

For each test case print the single integer on a separate line — the answer to the problem.

输入输出样例

  • 输入#1

    2
    2 2
    1 3

    输出#1

    4
    3

说明/提示

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.

首页