CF21D.Traveling Graph

提高+/省选-

通过率:0%

时间限制:0.50s

内存限制:64MB

AC君温馨提醒

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

题目描述

You are given undirected weighted graph. Find the length of the shortest cycle which starts from the vertex 1 and passes throught all the edges at least once. Graph may contain multiply edges between a pair of vertices and loops (edges from the vertex to itself).

给你一个无向带权图。请找出从顶点 1 出发、且至少经过每条边一次的最短环路的长度。该图中可能存在一对顶点之间的多条边(重边)以及自环(即从某个顶点指向其自身的边)。

输入格式

The first line of the input contains two integers n and m (1 ≤ n ≤ 15, 0 ≤ m ≤ 2000), n is the amount of vertices, and m is the amount of edges. Following m lines contain edges as a triples x, y, w (1 ≤ x, y ≤ n, 1 ≤ w ≤ 10000), x, y are edge endpoints, and w is the edge length.

输入的第一行包含两个整数 nn 和 mm(1 ≤ n ≤ 151 \le n \le 15,0 ≤ m ≤ 20000 \le m \le 2000),其中 nn 表示顶点数量,mm 表示边的数量。接下来的 mm 行每行描述一条边,格式为三元组 x, y, wx,\,y,\,w(1 ≤ x, y ≤ n1 \le x,\,y \le n,1 ≤ w ≤ 100001 \le w \le 10000),其中 xx 和 yy 是该边的两个端点,ww 是该边的长度。

输出格式

Output minimal cycle length or -1 if it doesn't exists.

输出最短环的长度,如果不存在环则输出 −1-1。

输入输出样例

  • 输入#1

    3 3
    1 2 1
    2 3 1
    3 1 1

    输出#1

    3
  • 输入#2

    3 2
    1 2 3
    2 3 4

    输出#2

    14

输入解题思路,AI测评打分。不知道怎么写?

首页