PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000007. Chuyển trang (Page Hopping)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chuyển trang (Page Hopping)

Page Hopping

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Directed links connect web pages. For every ordered pair of distinct pages with a route, consider the minimum clicks. Compute the mean over reachable ordered pairs.

Input

mm followed by mm directed links u,vu, v.

Output

Print the average with exactly three digits after the decimal point.

Subtasks

  • Subtask 1 (40 points): at most 1212 distinct pages; 1≤m≤20001\le m\le 2000; 1≤u,v≤1001\le u,v\le 100; u≠vu\ne v.
  • Subtask 2 (60 points): 1≤m≤20001\le m\le 2000; 1≤u,v≤1001\le u,v\le 100; u≠vu\ne v.

Examples

Input

3
1 2
2 3
3 1

Output

1.500

Explanation

Three ordered pairs require one click and three require two clicks. The mean is (3+6)/6=1.500(3+6)/6=1.500.