Problem:
Score : 600 points

Problem Statement

There is a cave consisting of N rooms and M one-directional passages. The rooms are numbered 1 through N.

Takahashi is now in Room 1, and Room N has the exit. The i-th passage connects Room s_i and Room t_i (s_i < t_i) and can only be traversed in the direction from Room s_i to Room t_i. It is known that, for each room except Room N, there is at least one passage going from that room.

Takahashi will escape from the cave. Each time he reaches a room (assume that he has reached Room 1 at the beginning), he will choose a passage uniformly at random from the ones going from that room and take that passage.

Aoki, a friend of Takahashi's, can block one of the passages (or do nothing) before Takahashi leaves Room 1. However, it is not allowed to block a passage so that Takahashi is potentially unable to reach Room N.

Let E be the expected number of passages Takahashi takes before he reaches Room N. Find the value of E when Aoki makes a choice that minimizes E.

Constraints

2 \leq N \leq 600

N-1 \leq M \leq \frac{N(N-1)}{2}

s_i < t_i

If i != j, (s_i, t_i) \neq (s_j, t_j). (Added 21:23 JST)

For every v = 1, 2, ..., N-1, there exists i such that v = s_i.

Input

Input is given from Standard Input in the following format:

N M
s_1 t_1
:
s_M t_M

Output

Print the value of E when Aoki makes a choice that minimizes E.
Your output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6}.

Sample Input 1

4 6
1 4
2 3
1 3
1 2
3 4
2 4

Sample Output 1

1.5000000000

If Aoki blocks the passage from Room 1 to Room 2, Takahashi will go along the path 1 → 3 → 4 with probability \frac{1}{2} and 1 → 4 with probability \frac{1}{2}. E = 1.5 here, and this is the minimum possible value of E.

Sample Input 2

3 2
1 2
2 3

Sample Output 2

2.0000000000

Blocking any one passage makes Takahashi unable to reach Room N, so Aoki cannot block a passage.

Sample Input 3

10 33
3 7
5 10
8 9
1 10
4 6
2 5
1 7
6 10
1 4
1 3
8 10
1 5
2 6
6 9
5 6
5 8
3 6
4 8
2 7
2 9
6 7
1 2
5 9
6 8
9 10
3 9
7 8
4 5
2 10
5 7
3 5
4 7
4 9

Sample Output 3

3.0133333333

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );

ll n,m;

struct Node{
  //set<ll> children;
  unordered_set<ll> children;
};

//vector< vector<ll> > influence;
vector< set<ll,greater<ll>> > influence;
vector<Node> graph;
vector<double> dp_origin;
vector<double> dp;

bool findPath(ll start,ll target){
  if(start==target) return true;
  queue<ll> que;
  que.push(start);
  while(!que.empty()){
    auto q=que.front();
    que.pop();
    for( auto x:graph[q].children ){
      if( x==target ) return true;
      else{
        if(x<target){
          que.push(x);
        }
      }
    }

  }
  return false;
}



double e(ll x){
  if(x==n) return dp_origin[x]=0.0;
  if( dp_origin[x]!=1e300 ) return dp_origin[x];

  ll num=graph[x].children.size();
  double expe=0.0;
  ll cnt=0;
  for(auto c:graph[x].children){
    double val=e(c);
    if(val!=1e300){
      expe += 1.0 * ( val +1.0);
      cnt++;
    }
  }

  return dp_origin[x]=expe/cnt;

}

double eRe(ll x ,ll target){
  //cout << x << endl;
  if(x==n) return dp[x]=0.0;
  if(x>target) return dp_origin[x];

  ll num=graph[x].children.size();
  if(num==0) return dp[x]=1e300;
  double expe=0.0;
  ll cnt=0;
  for(auto c:graph[x].children){
    double val=eRe(c,target);
    if(val==1e300) return 1e300;
      expe += 1.0 * ( val +1.0);
      cnt++;
  }
  if(cnt==0) return dp[x]=1e300;
  return dp[x]=expe/cnt;
}

vector<vector<double>> dp2d;
vector<double> dp_cut;

double dfs(ll ,ll);

int main(void){

  cin>>n>>m;
  vector< pair<ll,ll> > P(m);

  //rep(i,m) cin>>s[i]>>t[i];
  graph.resize(n+1);
  dp_origin.resize(n+1,1e300);
  dp.resize(n+1,1e300);
  rep(i,m){
    ll s,t;
    cin>>s>>t;
    graph[s].children.insert(t);
    
  }
  double ans=e(1);
  unordered_map<ll,ll> um;
  for(ll i=1;i<n;i++){
    for(auto c:graph[i].children){
      if(um.find(i)==end(um)) um[i]=c;
      else{
        if( dp_origin[um[i]] < dp_origin[c])  um[i]=c;
      }
    }
  }

  for(auto p:um)
  { 
    //cout << p.first << ","<< p.second << endl;
    ll x=p.first;
    //for(ll i=0;i<n+1;i++) dp_origin[i]=1e300;
    for(ll i=0;i<n+1;i++) dp[i]=dp_origin[i];
    graph[x].children.erase(p.second);
    //ans=min(ans,e(1));
    ans=min(ans,eRe(1,p.first));    
    graph[x].children.insert(p.second);
  }

  cout << setprecision(20) << ans << endl;

  return 0;

}



ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}