Language: C++

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template<class T>
void read(T&);
template<class T>
void write(const T&);

typedef long long ll;
typedef unsigned long long ull;
typedef const long long & cll;
typedef const int & ci;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;
using std::min;
using std::max;
using std::abs;
using std::sort;

const int N = 605;
const int M = 360005;

long double dp[N][M];
bool to[N][N];
int u[M], v[M];
int cnt[N];
int n, m;

int main () {
  read(n), read(m);
  for (int i = 1; i <= m; ++i) {
    read(u[i]), read(v[i]);
    to[u[i]][v[i]] = true;
    ++cnt[u[i]];
  }
  for (int i = n - 1; i >= 1; --i) {
    long double cnt = 0;
    for (int j = i + 1; j <= n; ++j) {
      cnt += to[i][j];
    }
    for (int j = 0; j <= m; ++j) {
      long double sum = 0;
      if (u[j] == i && cnt == 1) {
        dp[i][j] = 1e20;
        continue;
      }
      for (int k = i + 1; k <= n; ++k) {
        if (to[i][k]) {
          sum += dp[k][j];
        }
      }
      if (u[j] == i) {
        sum -= dp[v[j]][j];
        dp[i][j] = sum / (cnt - 1) + 1;
      } else {
        dp[i][j] = sum / cnt + 1;
      }
    }
  }
  long double ans = 1e15;
  for (int i = 0; i <= m; ++i) {
    ans = min(ans, dp[1][i]);
  }
  std::cout.precision(8);
  std::cout << std::fixed << ans << std::endl;
  return 0;
}

template<class T>
inline void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!isNum(ch)) {
    if (ch == '-') {
      flag = -1;
    }
    ch = getchar();
  }
  while (isNum(ch)) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template<class T>
inline void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}


Compiler output:
/tmp/cc4tLgJU.o: in function `main':
a.cc:(.text+0xb): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cc4tLgJU.o
a.cc:(.text+0x1a): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/cc4tLgJU.o
a.cc:(.text+0x42): relocation truncated to fit: R_X86_64_PC32 against symbol `u' defined in .bss section in /tmp/cc4tLgJU.o
a.cc:(.text+0x61): relocation truncated to fit: R_X86_64_PC32 against symbol `v' defined in .bss section in /tmp/cc4tLgJU.o
a.cc:(.text+0x80): relocation truncated to fit: R_X86_64_PC32 against symbol `u' defined in .bss section in /tmp/cc4tLgJU.o
a.cc:(.text+0x97): relocation truncated to fit: R_X86_64_PC32 against symbol `v' defined in .bss section in /tmp/cc4tLgJU.o
a.cc:(.text+0xb0): relocation truncated to fit: R_X86_64_PC32 against symbol `to' defined in .bss section in /tmp/cc4tLgJU.o
a.cc:(.text+0xca): relocation truncated to fit: R_X86_64_PC32 against symbol `u' defined in .bss section in /tmp/cc4tLgJU.o
a.cc:(.text+0xdf): relocation truncated to fit: R_X86_64_PC32 against symbol `cnt' defined in .bss section in /tmp/cc4tLgJU.o
a.cc:(.text+0xf6): relocation truncated to fit: R_X86_64_PC32 against symbol `cnt' defined in .bss section in /tmp/cc4tLgJU.o
a.cc:(.text+0x103): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status