A13357 | Tourism
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Masha lives in a country with $n$ cities numbered from $1$ to $n$ . She lives in the city number $1$ .
There is a direct train route between each pair of distinct cities $i$ and $j$ , where $i \neq j$ . In total there are $n(n-1)$ distinct routes. Every route has a cost, cost for route from $i$ to $j$ may be different from the cost of route from $j$ to $i$ .
Masha wants to start her journey in city $1$ , take exactly $k$ routes from one city to another and as a result return to the city $1$ . Masha is really careful with money, so she wants the journey to be as cheap as possible. To do so Masha doesn't mind visiting a city multiple times or even taking the same route multiple times.
Masha doesn't want her journey to have odd cycles. Formally, if you can select visited by Masha city $v$ , take odd number of routes used by Masha in her journey and return to the city $v$ , such journey is considered unsuccessful.
Help Masha to find the cheapest (with minimal total cost of all taken routes) successful journey.
There is a direct train route between each pair of distinct cities $i$ and $j$ , where $i \neq j$ . In total there are $n(n-1)$ distinct routes. Every route has a cost, cost for route from $i$ to $j$ may be different from the cost of route from $j$ to $i$ .
Masha wants to start her journey in city $1$ , take exactly $k$ routes from one city to another and as a result return to the city $1$ . Masha is really careful with money, so she wants the journey to be as cheap as possible. To do so Masha doesn't mind visiting a city multiple times or even taking the same route multiple times.
Masha doesn't want her journey to have odd cycles. Formally, if you can select visited by Masha city $v$ , take odd number of routes used by Masha in her journey and return to the city $v$ , such journey is considered unsuccessful.
Help Masha to find the cheapest (with minimal total cost of all taken routes) successful journey.
输入格式
First line of input had two integer numbers $n,k$ ( $2 \leq n \leq 80; 2 \leq k \leq 10$ ): number of cities in the country and number of routes in Masha's journey. It is guaranteed that $k$ is even.
Next $n$ lines hold route descriptions: $j$ -th number in $i$ -th line represents the cost of route from $i$ to $j$ if $i \neq j$ , and is 0 otherwise (there are no routes $i \to i$ ). All route costs are integers from $0$ to $10^8$ .
Next $n$ lines hold route descriptions: $j$ -th number in $i$ -th line represents the cost of route from $i$ to $j$ if $i \neq j$ , and is 0 otherwise (there are no routes $i \to i$ ). All route costs are integers from $0$ to $10^8$ .
输出格式
Output a single integer — total cost of the cheapest Masha's successful journey.
输入输出样例
输入 #1
5 8 0 1 2 2 0 0 0 1 1 2 0 1 0 0 0 2 1 1 0 0 2 0 1 2 0
输出 #1
2
输入 #2
3 2 0 1 1 2 0 1 2 2 0
输出 #2
3
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted