往期
- 【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_0:介绍了题目和背景
- 【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_1:题目输入的格式说明,选择了邻接表来表示图
- 【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_2:介绍了邻接表,题目输出的格式说明
这一期主要写一个初代程序,能完整一些简单的例子
0 程序
import sys
import heapq
from collections import defaultdict
def read_graph_from_stdin():
""" 从标准输入读取图数据并解析 """
lines = sys.stdin.read().strip().split("\n")
n = int(lines[0].strip()) # 节点数
s = int(lines[1].strip()) # 源点
k = int(lines[2].strip()) # 目标节点数
terminals = list(map(int, lines[3].strip().split()))