Exactly K Steps 2AI (CI翻译)
Problem Statement
There is a directed graph with $N$ vertices, vertex $1,$ vertex $2,\ldots,$ vertex $N$. For any pair of integers $(i,j)$ with $1 \leq i,j \leq N$, there is exactly one directed edge from vertex $i$ to vertex $j$ with cost $C_{i,j}$.
You are given a positive integer $K$. For each of $s=1,2,\ldots,N$, solve the following problem.
- Among the ways to start at vertex
$s$, move along an edge$K$times, and return to vertex$s$, find the minimum possible total cost of the edges traversed. More formally, find the minimum possible value of$\displaystyle\sum_{i=1}^{K}C_{v_{i-1},v_i}$for a sequence$v=(v_0,v_1,\ldots,v_K)$of integers between$1$and$N$, inclusive, of length$K+1$satisfying$v_0=v_K=s$.
Constraints
$1 \le N \le 100$$1 \le K \le 10^9$$0 \le C_{i,j} \le 10^9\ (1 \le i \le N,1 \le j \le N)$- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K
C_{1,1} C_{1,2} \ldots C_{1,N}
C_{2,1} C_{2,2} \ldots C_{2,N}
\vdots
C_{N,1} C_{N,2} \ldots C_{N,N}
Output
Output $N$ lines. The $i$-th line $(1 \le i \le N)$ should contain the answer to the problem for $s=i$.
{"titleZh":"恰好 K 步 2","bodyZh":"## 题目描述\n\n有一个包含 $N$ 个顶点的有向图,顶点编号为 $1,$ $2,\\ldots,$ $N$。对于任意满足 $1 \\leq i,j \\leq N$ 的整数对 $(i,j)$,都存在一条从顶点 $i$ 指向顶点 $j$、费用为 $C_{i,j}$ 的有向边。\n\n给定一个正整数 $K$。对于每个 $s=1,2,\\ldots,N$,请解决以下问题。\n\n- 从顶点 $s$ 出发,沿边移动 $K$ 次并回到顶点 $s$,求经过的边的总费用的最小值。更正式地说,对于一个长度为 $K+1$ 的整数序列 $v=(v_0,v_1,\\ldots,v_K)$,其中每个整数都在 $1$ 到 $N$(含)之间,且满足 $v_0=v_K=s$,求 $\displaystyle\\sum_{i=1}^{K}C_{v_{i-1},v_i}$ 的最小可能值。\n\n## 约束条件\n\n- $1 \\leq N \\leq 100$\n- $1 \\leq K \\leq 10^9$\n- $0 \\leq C_{i,j} \\leq 10^9\\ (1 \\leq i \\leq N,1 \\leq j \\leq N)$\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入从标准输入按以下格式给出:\n\n\n\n## 输出格式\n\n输出 \nN K\nC_{1,1} C_{1,2} \\ldots C_{1,N}\nC_{2,1} C_{2,2} \\ldots C_{2,N}\n\\vdots\nC_{N,1} C_{N,2} \\ldots C_{N,N}\n$N$ 行。第 $i$ 行 $(1 \\leq i \\leq N)$ 应包含当 $s=i$ 时问题的答案。"}AI (CI翻译)
样例
4 3
3 1 4 1
5 9 2 6
5 3 5 8
9 7 9 3
8
8
8
9
3 1000000000
100 999 999
999 100 999
999 999 100
100000000000
100000000000
100000000000
10 9482
748 169 586 329 972 529 432 519 408 587
138 249 656 114 632 299 984 755 404 772
155 506 832 854 353 465 387 374 567 385
631 556 951 428 104 705 530 406 258 102
709 325 334 193 520 798 749 582 337 910
530 110 659 635 786 773 811 468 810 638
111 822 554 627 395 959 924 698 777 893
142 848 532 781 711 814 665 395 960 290
746 266 603 553 893 353 323 640 172 263
749 921 845 334 594 821 233 695 109 951
1382481
1382481
1382628
1382481
1382481
1382540
1382481
1382739
1382499
1382481
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。