QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 256 MB Toplam puan: 100

#21255. Simplifying the Farm

İstatistikler

Farmer John has been taking an evening algorithms course at his local university, and he has just learned about minimum spanning trees. However, Farmer John now realizes that the design of his farm is not as efficient as it could be, and he wants to simplify the layout of his farm.

The farm is currently arranged like a graph, with vertices representing fields and edges representing pathways between these fields, each having an associated length. Farmer John notes that for each distinct length, at most three pathways on his farm share this length. FJ would like to remove some of the pathways on his farm so that it becomes a tree -- that is, so that there is one unique route between any pair of fields. Moreover, Farmer John would like this to be a minimum spanning tree -- a tree having the smallest possible sum of edge lengths.

Help Farmer John compute not only the sum of edge lengths in a minimum spanning tree derived from his farm graph, but also the number of different possible minimum spanning trees he can create.

Input

  • Line $1$: Two integers $N$ and $M$ $1 \le N \le 40,000; 1 \le M \le 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 \le a_{i}, b_{i} \le N; 1 \le n_{i} \le 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.

Output

  • Line $1$: Two integers representing the length of the minimal spanning tree and the number of minimal spanning trees (mod 1,000,000,007).

Examples

Input 1

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

Output 1

4 3

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

Problem credits: Nathan Pinsker, 2011

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.