#1017. 「USACO 2011.12 Gold」Simplifying the Farm

内存限制
512 MiB
时间限制
2000 ms
文件输入输出
simplify.in ≫ simplify.out
题目类型
传统
评测方式
文本比较
上传者 admin
题目来源 usaco

显示标签

题目描述

农夫约翰在一所夜校学习算法课程,他刚刚学会了最小生成树。现在约翰意识到他的农场设计得不够高效,他想简化农场的布局。

约翰的农场可以看做一个图,农田代表图中顶点,田间小路代表图中的边,每条边有一定的长度。约翰注意到,农场中最多有三条小路有着相同的长度。约翰想删除一些小路使得农场成为一棵树,使得两块农田间只有一条路径。但是约翰想把农场设计成最小生成树,也就是农场道路的总长度最短。

请帮助约翰找出最小生成树的总长度,同时请计算出总共有多少种最小生成树?

输入格式 simplify.in

* Line 1: Two integers N and M (1 <= N <= 40,000; 1 <= M <= 100,000), representing the number of vertices and edges in the farm graph, respectively. Vertices are numbered as 1..N.

* Lines 2..M+1: Three integers a_i, b_i and n_i (1 <= a_i, b_i <= N; 1 <= n_i <= 1,000,000) representing an edge from vertex a_i to b_i with length n_i. No edge length n_i will occur more than three times.

输出格式 simplify.out

* Line 1: Two integers representing the length of the minimal spanning tree and the number of minimal spanning trees (mod

1,000,000,007).

样例

输入 #1

4 5 
1 2 1 
3 4 1 
1 3 2 
1 4 2 
2 3 2

输出 #1

4 3

说明/提示

Picking both edges with length 1 and any edge with length 2 yields a minimum spanning tree of length 4.