Problem:
Problem B:
Cover Time
Let
G
be a connected undirected graph where
N
vertices of
G
are labeled by numbers from 1 to
N
.
G
is simple, i.e.
G
has no self loops or parallel edges.
Let
P
be a particle walking on vertices of
G
. At the beginning,
P
is on the vertex 1. In each step,
P
moves to one of the adjacent vertices. When there are multiple adjacent vertices, each is selected in the same
probability.
The
cover time
is the expected number of steps necessary for
P
to visit all the vertices.
Your task is to calculate the cover time for each given graph G.
Input
The input has the following format.
N M
a
1
b
1
.
.
.
a
M
b
M
N
is the number of vertices and
M
is the number of edges. You can assume that 2 ≤
N
≤ 10.
a
i
and
b
i
(1 ≤
i
≤
M
) are positive integers less than or equal to
N
, which represent the two vertices connected by the
i
-th edge. You can assume that the input satisfies the constraints written in the problem description, that is, the given graph
G
is connected and simple.
Output
There should be one line containing the cover time in the output.
The answer should be printed with six digits after the decimal point, and should not have an error greater than 10
-6
.
Sample Input and Output
Input #1
3 2
1 2
2 3
Output #1
4.000000
Input #2
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output #2
5.500000

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

int n , m  , ed;
double dp[10][1 << 10][1705];
vector < int > E[15];

inline void updata(double & x , double v){
	x += v;
}

int main(int argc , char *argv[]){
	scanf("%d%d",&n,&m);ed = 1 << n;
	for(int i = 1 ; i <= m ; ++ i){
		int u , v ;
		scanf("%d%d",&u,&v);u--,v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dp[0][1][0] = 1;
	for(int k = 0 ; k < 1700 ; ++ k)
		for(int i = 0 ; i < n ; ++ i)
			for(int j = 0 ; j < ed - 1; ++ j){
				if(E[i].size() == 0) continue;
				double p = (double)1/E[i].size();
				for(int vv = 0 ; vv < E[i].size() ; ++ vv){
					int v = E[i][vv];
					updata( dp[v][j | (1 << v)][k + 1] , dp[i][j][k] * p);
				}
			}
	double ans = 0;
	for(int i = 0 ; i < 1700 ; ++ i){
		double PX = 0;
		for(int j = 0 ; j < n ; ++ j) PX += dp[j][ed-1][i];
		ans += PX*i;
	}
	printf("%.6lf\n",ans);
	return 0;
}
accuracy: 1
time_ms: 330
memory_kb: 131064
final_rank: 8

code_snippet: //#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <bitset>
#include <string>
using namespace std;
double esp=1e-11;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define cle(a) while(!a.empty())a.pop()
#define mem(p) memset(p,0,sizeof(p))
#define memf(p) memset(p,0x3f,sizeof(p))
#define memn(p) memset(p,-1,sizeof(p))
#define mp(A, B) make_pair(A, B)
#define pb push_back
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
typedef long long int LL;
const double PI = acos(-1.0);
const LL INF=0x3f3f3f3f;
const LL MOD =1e9+7;
const int maxn =10100;
struct point{
int u,st,stp;
point(){};
point(int u,int st,int stp){this->u=u;this->st=st;this->stp=stp;};
bool operator <(const point&a) const  {  return u < a.u||(u==a.u&&stp<a.stp)||(u==a.u&&stp==a.stp&&st<a.st); }
};
vector<int>l[15];
int s[15];
queue<point>q;
map<point ,double>mpp;
double ans=0;
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("trees.in", "r", stdin);
    //freopen("trees.out", "w", stdout);
    //map<long long int,int>ma;                 %lld
    //vector<int>::iterator iter;
    //memset(m,0,sizeof(int));               for(iter=trtr[rt].begin();iter!=trtr[rt].end();iter++)
    //for(int x=1;x<=n;x++)
    //for(int y=1;y<=n;y++)
    //scanf("%d%d",&a,&b);
    //scanf("%d",&n);
    //printf("%d\n",ans);
    int n,m;
    scanf("%d%d",&n,&m);
    mem(l);
    mem(s);
    int u,v;
    for(int x=1;x<=n;x++)
        l[x].clear();
    for(int x=1;x<=m;x++)
    {
        scanf("%d%d",&u,&v);
        u--;v--;
        l[u].pb(v);
        l[v].pb(u);
        s[u]++;
        s[v]++;
    }
    cle(q);
    point tem=point(0,1,0);
    mpp.clear();
    q.push(tem);
    mpp[tem]=1.0;
    int cnt=500000;
    int x;
    while(cnt--&&!q.empty())
    {
        u=q.front().u;
        if(q.front().st==(1<<n)-1)
        {
            ans+=q.front().stp*mpp[q.front()];     //printf("%d %d %d %.6f\n",q.front().u,q.front().st,q.front().stp,q.front().p);
        }
        else
        {
            for(x=0;x<s[u];x++)
            {
                tem=point(l[u][x],q.front().st|(1<<l[u][x]),q.front().stp+1);
                if(mpp.find(tem)==mpp.end())q.push(tem);
                mpp[tem]+=mpp[q.front()]/s[u];
            }
        }
        mpp.erase(q.front());
        q.pop();
    }
    printf("%.6f\n",ans);
    return 0;
}
accuracy: 0.05
time_ms: 270
memory_kb: 3620
final_rank: 19

code_snippet: #include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define MAXN 15
#define MAXM 1000010
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
typedef long long LL;

int n,m,cnt[MAXN];
bool Map[MAXN][MAXN];
double f[2][2000][MAXN][2];

void Init()
{
    int i,u,v;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;++i){
        scanf("%d%d",&u,&v); --u; --v;
        Map[u][v]=Map[v][u]=true;
        ++cnt[u]; ++cnt[v];
    }
}

void DP()
{
    int i,u,v,k,t,c;
    double ans=0,pre=0;
    f[0][1][0][1]=1;
    for(k=t=1;;k^=1,++t){
        memset(f[k],0,sizeof(f[k]));
        for(i=1;i<(1<<n)-1;++i)
            for(u=0;u<n;++u){
                if(!((1<<u)&i)) continue;
                for(v=0;v<n;++v){
                    if(!Map[u][v]) continue;
                    f[k][i|(1<<v)][v][0]+=f[k^1][i][u][0]/cnt[u]+f[k^1][i][u][1]/cnt[u];
                    f[k][i|(1<<v)][v][1]+=f[k^1][i][u][1]/cnt[u];
                }
            }
        for(u=ans=0;u<n;++u){
            f[k][(1<<n)-1][u][0]+=f[k^1][(1<<n)-1][u][0];
            f[k][(1<<n)-1][u][1]+=f[k^1][(1<<n)-1][u][1];
        }
        for(u=ans=0;u<n;++u) ans+=f[k][(1<<n)-1][u][0];
        if(t>n&&fabs(ans-pre)<1e-7){
            if((++c)>50) break;
        }
        else c=0;
        pre=ans;
    }
    printf("%.6f\n",ans);
}

int main()
{
    Init();
    DP();
    return 0;
}
accuracy: 0.05
time_ms: 80
memory_kb: 3888
final_rank: 18

code_snippet: #include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define MAXN 15
#define MAXM 1000010
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
typedef long long LL;

int n,m,cnt[MAXN];
bool Map[MAXN][MAXN];
double f[2][2000][MAXN][2];

void Init()
{
    int i,u,v;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;++i){
        scanf("%d%d",&u,&v); --u; --v;
        Map[u][v]=Map[v][u]=true;
        ++cnt[u]; ++cnt[v];
    }
}

void DP()
{
    int i,u,v,k,t,c;
    double ans=0,pre=0;
    f[0][1][0][1]=1;
    for(k=t=1;;k^=1,++t){
        memset(f[k],0,sizeof(f[k]));
        for(i=1;i<(1<<n)-1;++i)
            for(u=0;u<n;++u){
                if(!((1<<u)&i)) continue;
                for(v=0;v<n;++v){
                    if(!Map[u][v]) continue;
                    f[k][i|(1<<v)][v][0]+=f[k^1][i][u][0]/cnt[u]+f[k^1][i][u][1]/cnt[u];
                    f[k][i|(1<<v)][v][1]+=f[k^1][i][u][1]/cnt[u];
                }
            }
        for(u=ans=0;u<n;++u){
            f[k][(1<<n)-1][u][0]+=f[k^1][(1<<n)-1][u][0];
            f[k][(1<<n)-1][u][1]+=f[k^1][(1<<n)-1][u][1];
        }
        for(u=ans=0;u<n;++u) ans+=f[k][(1<<n)-1][u][0];
        if(t>n&&fabs(ans-pre)<1e-7){
            if((++c)>70) break;
        }
        else c=0;
        pre=ans;
    }
    printf("%.6f\n",ans);
}

int main()
{
    Init();
    DP();
    return 0;
}
accuracy: 0.05
time_ms: 80
memory_kb: 3800
final_rank: 17

code_snippet: #include <bits/stdc++.h>

using namespace std;

const int limit=1e4;
int n,m;
vector<int> e[20];
double dp[2][10][1<<10];

int main()
{
    if(n==2)
    {
        printf("1.000000\n");
        return 0;
    }
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        x--,y--;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    int cnt=1,t=1;
    double tmp=0,ans=0;
    dp[0][0][1]=1.0;
    while(cnt<limit)
    {
        memset(dp[t],0,sizeof(dp[t]));
        for(int i=0;i<n;i++)
        {
            for(int p=0;p<(1<<n)-1;p++)
            {
                for(int k=0;k<e[i].size();k++)
                {
                    int j=e[i][k];
                    dp[t][j][p|(1<<j)]+=dp[t^1][i][p]/(1.0*e[i].size());
                }
            }
        }
        tmp=0;
        for(int i=0;i<n;i++)
            tmp+=dp[t][i][(1<<n)-1];
        ans+=tmp*cnt;
        cnt++,t^=1;
    }
    printf("%.6f\n",ans);
    return 0;
}
accuracy: 1
time_ms: 5510
memory_kb: 3732
final_rank: 4

code_snippet: #include <cstdio>
#include <vector>

using namespace std;

vector<int> G[10];
vector<pair<int, double> > mat[10240];
pair<int, int> f[10240];
int id[1024][10];
int cnt;
double dp[2][10240];

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	while (m--)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		u--, v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for (int i = 0; i < (1 << n); ++i)
	{
		if (i == (1 << n) - 1)
		{
			for (int j = 0; j < n; ++j)
			{
				id[i][j] = cnt;
			}
		}
		else
		{
			for (int j = 0; j < n; ++j)
			{
				if ((i & 1) && (i >> j & 1))
				{
					id[i][j] = cnt;
					f[cnt++] = {i, j};
				}
				else
				{
					id[i][j] = -1;
				}
			}
		}
	}
	for (int i = 0; i < cnt; ++i)
	{
		int j = f[i].first, u = f[i].second;
		for (int v: G[u])
		{
			mat[i].push_back({id[j | (1 << v)][v], 1.0 / G[u].size()});
		}
	}
	auto &x = dp[0], &y = dp[1];
	y[0] = 1;
	double ans = 0;
	for (int it = 1; it <= 1e3; ++it)
	{
		swap(x, y);
		for (int i = 0; i <= cnt; ++i)
		{
			y[i] = 0;
		}
		for (int i = 0; i < cnt; ++i)
		{
			for (auto p: mat[i])
			{
				y[p.first] += x[i] * p.second;
			}
		}
		ans += y[cnt] * it;
	}
	printf("%.10f\n", ans);
	return 0;
}
accuracy: 0.8
time_ms: 40
memory_kb: 4176
final_rank: 9

code_snippet: // AOJ #2469
// Cover Time 2025.1.24

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int N, M;
    cin >> N >> M;
    // Use 0-based indexing
    vector<vector<int>> adj(N, vector<int>());
    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int total_states = 1 << N;
    // Each state is (v, S) where v from 0 to N-1, S includes v
    // Total variables: N * (1<<N)
    int K = N * total_states;
    // Initialize two arrays
    vector<double> E_prev(K, 0.0);
    vector<double> E_next(K, 0.0);
    // For all states where S includes v, initialize E_prev to 0 if S is all, else 0
    // No need to initialize as already 0
    double epsilon = 1e-9;
    double max_diff = 1.0;
    int iterations = 0;
    int max_iterations = 100000;
    while(max_diff > 1e-8 && iterations < max_iterations){
        max_diff = 0.0;
        for(int S=0; S < total_states; S++){
            for(int v=0; v < N; v++){
                if( (S & (1<<v)) == 0 ){
                    continue; // invalid state, S must include v
                }
                int idx = v * total_states + S;
                if(S == ( (1<<N) -1 )){
                    // E[v][S] = 0
                    if(abs(E_prev[idx]) > max_diff){
                        max_diff = abs(E_prev[idx]);
                    }
                    E_next[idx] = 0.0;
                }
                else{
                    int deg = adj[v].size();
                    if(deg == 0){
                        // No way to move, but since graph is connected, this shouldn't happen
                        // To prevent division by zero, set E to a large number
                        E_next[idx] = 1e18;
                        max_diff = max(max_diff, abs(E_prev[idx] - E_next[idx]));
                        continue;
                    }
                    double sum = 0.0;
                    for(auto &u: adj[v]){
                        int S_new = S | (1<<u);
                        int new_idx = u * total_states + S_new;
                        sum += E_prev[new_idx];
                    }
                    double E_new = 1.0 + (sum / adj[v].size());
                    double diff = abs(E_prev[idx] - E_new);
                    if(diff > max_diff){
                        max_diff = diff;
                    }
                    E_next[idx] = E_new;
                }
            }
        }
        // Swap E_prev and E_next
        swap(E_prev, E_next);
        iterations++;
    }
    // Initial state: at vertex 0 (vertex 1), with S = {0} -> S = 1<<0 =1
    int initial_v = 0;
    int initial_S = 1<<0;
    int initial_idx = initial_v * total_states + initial_S;
    double answer = E_prev[initial_idx];
    // Print with six decimal places
    cout << fixed << setprecision(8) << answer << '\n';
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3712
final_rank: 1

code_snippet: #include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define MAXN 15
#define MAXM 1000010
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
typedef long long LL;

int n,m,cnt[MAXN];
bool Map[MAXN][MAXN];
double f[2][2000][MAXN][2];

void Init()
{
    int i,u,v;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;++i){
        scanf("%d%d",&u,&v); --u; --v;
        Map[u][v]=Map[v][u]=true;
        ++cnt[u]; ++cnt[v];
    }
}

void DP()
{
    int i,u,v,k,t,c;
    double ans=0,pre=0;
    f[0][1][0][1]=1;
    for(k=t=1;;k^=1,++t){
        memset(f[k],0,sizeof(f[k]));
        for(i=1;i<(1<<n)-1;++i)
            for(u=0;u<n;++u){
                if(!((1<<u)&i)) continue;
                for(v=0;v<n;++v){
                    if(!Map[u][v]) continue;
                    f[k][i|(1<<v)][v][0]+=f[k^1][i][u][0]/cnt[u]+f[k^1][i][u][1]/cnt[u];
                    f[k][i|(1<<v)][v][1]+=f[k^1][i][u][1]/cnt[u];
                }
            }
        for(u=ans=0;u<n;++u){
            f[k][(1<<n)-1][u][0]+=f[k^1][(1<<n)-1][u][0];
            f[k][(1<<n)-1][u][1]+=f[k^1][(1<<n)-1][u][1];
        }
        for(u=ans=0;u<n;++u) ans+=f[k][(1<<n)-1][u][0];
        if(t>n&&fabs(ans-pre)<1e-7){
            if((++c)>80) break;
        }
        else c=0;
        pre=ans;
    }
    printf("%.6f\n",ans);
}

int main()
{
    Init();
    DP();
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3684
final_rank: 2

code_snippet: #include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define MAXN 15
#define MAXM 1000010
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
typedef long long LL;

int n,m,cnt[MAXN];
bool Map[MAXN][MAXN];
double f[2][2000][MAXN][2];

void Init()
{
    int i,u,v;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;++i){
        scanf("%d%d",&u,&v); --u; --v;
        Map[u][v]=Map[v][u]=true;
        ++cnt[u]; ++cnt[v];
    }
}

void DP()
{
    int i,u,v,k,t,c;
    double ans=0,pre=0;
    f[0][1][0][1]=1;
    for(k=t=1;;k^=1,++t){
        memset(f[k],0,sizeof(f[k]));
        for(i=1;i<(1<<n)-1;++i)
            for(u=0;u<n;++u){
                if(!((1<<u)&i)) continue;
                for(v=0;v<n;++v){
                    if(!Map[u][v]) continue;
                    f[k][i|(1<<v)][v][0]+=f[k^1][i][u][0]/cnt[u]+f[k^1][i][u][1]/cnt[u];
                    f[k][i|(1<<v)][v][1]+=f[k^1][i][u][1]/cnt[u];
                }
            }
        for(u=ans=0;u<n;++u){
            f[k][(1<<n)-1][u][0]+=f[k^1][(1<<n)-1][u][0];
            f[k][(1<<n)-1][u][1]+=f[k^1][(1<<n)-1][u][1];
        }
        for(u=ans=0;u<n;++u) ans+=f[k][(1<<n)-1][u][0];
        if(t>n&&fabs(ans-pre)<1e-7){
            if((++c)>100) break;
        }
        else c=0;
        pre=ans;
    }
    printf("%.6f\n",ans);
}

int main()
{
    Init();
    DP();
    return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 3660
final_rank: 3

code_snippet: #include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define MAXN 15
#define MAXM 1000010
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
typedef long long LL;

int n,m,cnt[MAXN];
bool Map[MAXN][MAXN];
double f[2][2000][MAXN][2];

void Init()
{
    int i,u,v;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;++i){
        scanf("%d%d",&u,&v); --u; --v;
        Map[u][v]=Map[v][u]=true;
        ++cnt[u]; ++cnt[v];
    }
}

void DP()
{
    int i,u,v,k,t;
    double ans=0,pre;
    f[0][1][0][1]=1;
    for(k=t=1;;k^=1,++t){
        memset(f[k],0,sizeof(f[k]));
        for(i=1;i<(1<<n)-1;++i)
            for(u=0;u<n;++u){
                if(!((1<<u)&i)) continue;
                for(v=0;v<n;++v){
                    if(!Map[u][v]) continue;
                    f[k][i|(1<<v)][v][0]+=f[k^1][i][u][0]/cnt[u]+f[k^1][i][u][1]/cnt[u];
                    f[k][i|(1<<v)][v][1]+=f[k^1][i][u][1]/cnt[u];
                }
            }
        for(u=ans=0;u<n;++u){
            f[k][(1<<n)-1][u][0]+=f[k^1][(1<<n)-1][u][0];
            f[k][(1<<n)-1][u][1]+=f[k^1][(1<<n)-1][u][1];
        }
        for(u=ans=0;u<n;++u) ans+=f[k][(1<<n)-1][u][0];
        if(t>1000&&ans==pre) break; pre=ans;
    }
    printf("%.6f\n",ans);
}

int main()
{
    Init();
    DP();
    return 0;
}
accuracy: 0.8
time_ms: 430
memory_kb: 3684
final_rank: 11

code_snippet: #include <bits/stdc++.h>
#define INF 1000000007
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
const double EPS = 1e-9, PI = acos(-1.0);
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 100010;
int n, m, goal;
bool g[10][10];
double ans, num[10];
double dp[2][1 << 10][10];
void solve(double now[1 << 10][10], double nxt[1 << 10][10], int len)
{
    for(int i = 1; i <= goal; ++i)
		for(int j = 0; j < n; ++j)
			nxt[i][j] = 0.0;
    for(int i = 1; i < goal; ++i)
        for(int j = 0; j < n; ++j) if(i & (1 << j))
                for(int k = 0; k < n; ++k)
                    if(g[j][k])
                        nxt[i | (1 << k)][k] += num[j] * now[i][j];
	for(int i = 0; i < n; ++i) ans += nxt[goal][i] * len;
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
#endif
    scanf("%d%d", &n, &m);
    for(int i = 0, u, v; i < m; ++i)
    {
        scanf("%d%d", &u, &v);
        --u, --v;
        g[u][v] = g[v][u] = true;
        num[u] += 1.0;
        num[v] += 1.0;
    }
    for(int i = 0; i < n; ++i) if(num[i]) num[i] = 1.0 / num[i];
    goal = (1 << n) - 1;
    dp[0][1][0] = 1.0;
    for(int i = 1, j = 0; i < 10000; ++i, j = !j) solve(dp[j], dp[!j], i);
    printf("%.6f", ans);
    return 0;
}
accuracy: 1
time_ms: 6180
memory_kb: 1384
final_rank: 6

code_snippet: #include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define MAXN 15
#define MAXM 1000010
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
typedef long long LL;

int n,m,cnt[MAXN];
bool Map[MAXN][MAXN];
double f[2][2000][MAXN][2];

void Init()
{
    int i,u,v;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;++i){
        scanf("%d%d",&u,&v); --u; --v;
        Map[u][v]=Map[v][u]=true;
        ++cnt[u]; ++cnt[v];
    }
}

void DP()
{
    int i,u,v,k,t;
    double ans=0;
    f[0][1][0][1]=1;
    for(k=t=1;t<=1000;k^=1,++t){
        memset(f[k],0,sizeof(f[k]));
        for(i=1;i<(1<<n)-1;++i)
            for(u=0;u<n;++u){
                if(!((1<<u)&i)) continue;
                for(v=0;v<n;++v){
                    if(!Map[u][v]) continue;
                    f[k][i|(1<<v)][v][0]+=f[k^1][i][u][0]/cnt[u]+f[k^1][i][u][1]/cnt[u];
                    f[k][i|(1<<v)][v][1]+=f[k^1][i][u][1]/cnt[u];
                }
            }
        for(u=ans=0;u<n;++u){
            f[k][(1<<n)-1][u][0]+=f[k^1][(1<<n)-1][u][0];
            f[k][(1<<n)-1][u][1]+=f[k^1][(1<<n)-1][u][1];
        }
    }
    for(u=ans=0;u<n;++u) ans+=f[k^1][(1<<n)-1][u][0];
    printf("%.6f\n",ans);
}

int main()
{
    Init();
    DP();
    return 0;
}
accuracy: 0.8
time_ms: 440
memory_kb: 3684
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;

const int limit=15;
int n,m;
vector<int> e[20];

double dfs(int x,int p,int t)
{
    if(t==(1<<n)-1||p>limit)
    {
        return 1.0*p;
    }
    double ret=0;
    for(int i=0;i<e[x].size();i++)
    {
        int y=e[x][i];
        ret+=dfs(y,p+1,t|(1<<y))/(1.0*e[x].size());
    }
    return ret;
}

int main()
{
    if(n==2)
    {
        printf("1.000000\n");
        return 0;
    }
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        x--,y--;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    double ans;
    ans=dfs(0,0,1)*(1.0*(n-2));
  //  printf("%.6f\n",ans);
    ans=ceil(ans);
    ans/=(1.0*(n-2));
    printf("%.6f\n",ans);
    return 0;
}
accuracy: 0.05
time_ms: 1930
memory_kb: 1240
final_rank: 20

code_snippet: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int N=1e5+10;
const double eps=1e-11;
double a[2][1<<10][10];
vector<int>v[10];
queue<int>q,q1;
int main()
{
    int n,m,i,j,l,k;
    double ans=0;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        v[x-1].push_back(y-1);
        v[y-1].push_back(x-1);
    }
    memset(a[0],0,sizeof a[0]);
    a[0][1][0]=1.0;
    for(k=1;k<=1000;k++)
    {
        memset(a[k%2],0,sizeof a[k%2]);
        for(i=1;i<(1<<n)-1;i++)
            for(j=0;j<n;j++)
            if(a[(k+1)%2][i][j]>eps)
                for(l=0;l<v[j].size();l++)a[k%2][i|(1<<v[j][l])][v[j][l]]+=a[(k+1)%2][i][j]/(1.0*v[j].size());
        for(i=0;i<n;i++)ans+=k*a[k%2][(1<<n)-1][i];
    }
    printf("%.10lf\n",ans);
    return 0;
}
accuracy: 0.05
time_ms: 10
memory_kb: 1440
final_rank: 16

code_snippet: #include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int g[10][10];
int cnt[10];

int main(){
  const int n = getInt();
  const int m = getInt();

  REP(i,m){
    const int a = getInt() - 1;
    const int b = getInt() - 1;
    g[a][b] = g[b][a] = 1;
    cnt[a]++; cnt[b]++;
  }

  const int lim = 10000;
  double ans = 0.0;

  vector<vector<double> > dp(1 << n, vector<double>(n));
  dp[1][0] = 1.0;

  REP(cc, lim){
    vector<vector<double> > next(1 << n, vector<double>(n));

    REP(i,1<<n) REP(j,n) if(dp[i][j] > 0.0){
      if(i == (1 << n) - 1){
        ans += dp[i][j] * cc;
      }else{
        REP(k,n) if(g[j][k]){
          next[i | (1 << k)][k] += dp[i][j] / cnt[j];
        }
      }
    }

    dp.swap(next);
  }

  printf("%.8f\n", ans);

  return 0;
}
accuracy: 1
time_ms: 7700
memory_kb: 1332
final_rank: 7

code_snippet: #include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int g[10][10];
int cnt[10];

int main(){
  const int n = getInt();
  const int m = getInt();

  REP(i,m){
    const int a = getInt() - 1;
    const int b = getInt() - 1;
    g[a][b] = g[b][a] = 1;
    cnt[a]++; cnt[b]++;
  }

  const int lim = 1000;
  double ans = 0.0;

  vector<vector<double> > dp(1 << n, vector<double>(n));
  dp[1][0] = 1.0;

  REP(cc, lim){
    vector<vector<double> > next(1 << n, vector<double>(n));

    REP(i,1<<n) REP(j,n) if(dp[i][j] > 0.0){
      if(i == (1 << n) - 1){
        ans += dp[i][j] * cc;
      }else{
        REP(k,n) if(g[j][k]){
          next[i | (1 << k)][k] += dp[i][j] / cnt[j];
        }
      }
    }

    dp.swap(next);
  }

  printf("%.8f\n", ans);

  return 0;
}
accuracy: 0.8
time_ms: 210
memory_kb: 1332
final_rank: 10

code_snippet: #include<cmath>
#include<cstdio>
#include<vector>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int N_MAX=2850; // 2800->RE, 2900->MLE

void Gauss_Jordan(int n,double A[N_MAX][N_MAX+1],const double *b,double *x){
	rep(i,n) A[i][n]=b[i];

	rep(i,n){
		int piv=i;
		for(int j=i;j<n;j++) if(abs(A[j][i])>abs(A[piv][i])) piv=j;
		rep(j,n+1) swap(A[i][j],A[piv][j]);

		for(int j=i+1;j<=n;j++) A[i][j]/=A[i][i];
		rep(j,n) if(i!=j) for(int k=i+1;k<=n;k++) A[j][k]-=A[j][i]*A[i][k];
	}

	rep(i,n) x[i]=A[i][n];
}

void Gauss_Seidel(int n,const double A[N_MAX][N_MAX+1],const double *b,double *x){
	rep(_,300){
		rep(i,n){
			double y=b[i];
			rep(j,n) if(j!=i) y-=A[i][j]*x[j];
			x[i]=y/A[i][i];
		}
	}
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	bool G[10][10]={};
	int deg[10]={};
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		G[u][v]=G[v][u]=true;
		deg[u]++;
		deg[v]++;
	}

	vector<int> V; // 訪問済みの頂点集合としてありえるもの全体
	rep(S,1<<n){
		if((S&1)==0) continue;

		bool vis[10]={true};
		int Q[10],head=0,tail=0;
		Q[tail++]=0;
		while(head<tail){
			int u=Q[head++];
			rep(v,n) if(G[u][v] && !vis[v] && (S>>v)&1) {
				vis[v]=true;
				Q[tail++]=v;
			}
		}

		bool ok=true;
		rep(u,n) if(((S>>u)&1)!=vis[u]) ok=false;
		if(ok) V.push_back(S);
	}

	int k=0;
	vector< pair<int,int> > T; // ありうる状態の全体 ( 訪問済みの頂点集合と今いる頂点のペア )
	int id[1<<10][10]; // T の逆写像
	rep(i,V.size()) rep(u,n) if((V[i]>>u)&1) {
		T.push_back(make_pair(V[i],u));
		id[V[i]][u]=k++;
	}

	// x[i] := 状態 i からスタートして全頂点を巡り終える時刻の期待値
	static double A[N_MAX][N_MAX+1],b[N_MAX],x[N_MAX];
	rep(i,k){
		int S=T[i].first,u=T[i].second;
		if(S!=(1<<n)-1){
			rep(v,n) if(G[u][v]) {
				int S2=S;
				if(((S>>v)&1)==0) S2|=1<<v;
				int j=id[S2][v];
				A[i][j]=-1.0/deg[u];
			}
			A[i][i]=1;
			b[i]=1;
		}
		else{ // 全頂点を巡り終えた状態
			A[i][i]=1;
		}
	}

	rep(u,k) x[u]=1; // 適当な初期ベクトル

	if(k<2000) Gauss_Jordan(k,A,b,x);
	else       Gauss_Seidel(k,A,b,x);

	printf("%.9f\n",x[0]);

	return 0;
}
accuracy: 1
time_ms: 2320
memory_kb: 63816
final_rank: 5

code_snippet: #include<cmath>
#include<cstdio>
#include<vector>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int N_MAX=2800;

void Gauss_Jordan(int n,double A[N_MAX][N_MAX+1],const double *b,double *x){
	rep(i,n) A[i][n]=b[i];

	rep(i,n){
		int piv=i;
		for(int j=i;j<n;j++) if(abs(A[j][i])>abs(A[piv][i])) piv=j;
		rep(j,n+1) swap(A[i][j],A[piv][j]);

		for(int j=i+1;j<=n;j++) A[i][j]/=A[i][i];
		rep(j,n) if(i!=j) for(int k=i+1;k<=n;k++) A[j][k]-=A[j][i]*A[i][k];
	}

	rep(i,n) x[i]=A[i][n];
}

void Gauss_Seidel(int n,const double A[N_MAX][N_MAX+1],const double *b,double *x){
	rep(_,300){
		rep(i,n){
			double y=b[i];
			rep(j,n) if(j!=i) y-=A[i][j]*x[j];
			x[i]=y/A[i][i];
		}
	}
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	bool G[10][10]={};
	int deg[10]={};
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		G[u][v]=G[v][u]=true;
		deg[u]++;
		deg[v]++;
	}

	vector<int> V; // 訪問済みの頂点集合としてありえるもの全体
	rep(S,1<<n){
		if((S&1)==0) continue;

		bool vis[10]={true};
		int Q[10],head=0,tail=0;
		Q[tail++]=0;
		while(head<tail){
			int u=Q[head++];
			rep(v,n) if(G[u][v] && !vis[v] && (S>>v)&1) {
				vis[v]=true;
				Q[tail++]=v;
			}
		}

		bool ok=true;
		rep(u,n) if(((S>>u)&1)!=vis[u]) ok=false;
		if(ok) V.push_back(S);
	}

	int k=0;
	vector< pair<int,int> > T; // ありうる状態の全体 ( 訪問済みの頂点集合と今いる頂点のペア )
	int id[1<<10][10]; // T の逆写像
	rep(i,V.size()) rep(u,n) if((V[i]>>u)&1) {
		T.push_back(make_pair(V[i],u));
		id[V[i]][u]=k++;
	}

	// x[i] := 状態 i からスタートして全頂点を巡り終える時刻の期待値
	static double A[N_MAX][N_MAX+1],b[N_MAX],x[N_MAX];
	rep(i,k){
		int S=T[i].first,u=T[i].second;
		if(S!=(1<<n)-1){
			rep(v,n) if(G[u][v]) {
				int S2=S;
				if(((S>>v)&1)==0) S2|=1<<v;
				int j=id[S2][v];
				A[i][j]=-1.0/deg[u];
			}
			A[i][i]=1;
			b[i]=1;
		}
		else{ // 全頂点を巡り終えた状態
			A[i][i]=1;
		}
	}

	rep(u,k) x[u]=1; // 適当な初期ベクトル

	if(k<2000) Gauss_Jordan(k,A,b,x);
	else       Gauss_Seidel(k,A,b,x);

	printf("%.9f\n",x[0]);

	return 0;
}
accuracy: 0.35
time_ms: 2330
memory_kb: 59900
final_rank: 13

code_snippet: #include<cmath>
#include<cstdio>
#include<vector>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int N_MAX=2500;

void Gauss_Jordan(int n,double A[N_MAX][N_MAX+1],const double *b,double *x){
	rep(i,n) A[i][n]=b[i];

	rep(i,n){
		int piv=i;
		for(int j=i;j<n;j++) if(abs(A[j][i])>abs(A[piv][i])) piv=j;
		rep(j,n+1) swap(A[i][j],A[piv][j]);

		for(int j=i+1;j<=n;j++) A[i][j]/=A[i][i];
		rep(j,n) if(i!=j) for(int k=i+1;k<=n;k++) A[j][k]-=A[j][i]*A[i][k];
	}

	rep(i,n) x[i]=A[i][n];
}

void Gauss_Seidel(int n,const double A[N_MAX][N_MAX+1],const double *b,double *x){
	rep(_,300){
		rep(i,n){
			double y=b[i];
			rep(j,n) if(j!=i) y-=A[i][j]*x[j];
			x[i]=y/A[i][i];
		}
	}
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	bool G[10][10]={};
	int deg[10]={};
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		G[u][v]=G[v][u]=true;
		deg[u]++;
		deg[v]++;
	}

	vector<int> V; // 訪問済みの頂点集合としてありえるもの全体
	rep(S,1<<n){
		if((S&1)==0) continue;

		bool vis[10]={true};
		int Q[10],head=0,tail=0;
		Q[tail++]=0;
		while(head<tail){
			int u=Q[head++];
			rep(v,n) if(G[u][v] && !vis[v] && (S>>v)&1) {
				vis[v]=true;
				Q[tail++]=v;
			}
		}

		bool ok=true;
		rep(u,n) if(((S>>u)&1)!=vis[u]) ok=false;
		if(ok) V.push_back(S);
	}

	int k=0;
	vector< pair<int,int> > T; // ありうる状態の全体 ( 訪問済みの頂点集合と今いる頂点のペア )
	int id[1<<10][10]; // T の逆写像
	rep(i,V.size()) rep(u,n) if((V[i]>>u)&1) {
		T.push_back(make_pair(V[i],u));
		id[V[i]][u]=k++;
	}

	// x[i] := 状態 i からスタートして全頂点を巡り終える時刻の期待値
	static double A[N_MAX][N_MAX+1],b[N_MAX],x[N_MAX];
	rep(i,k){
		int S=T[i].first,u=T[i].second;
		if(S!=(1<<n)-1){
			rep(v,n) if(G[u][v]) {
				int S2=S;
				if(((S>>v)&1)==0) S2|=1<<v;
				int j=id[S2][v];
				A[i][j]=-1.0/deg[u];
			}
			A[i][i]=1;
			b[i]=1;
		}
		else{ // 全頂点を巡り終えた状態
			A[i][i]=1;
		}
	}

	rep(u,k) x[u]=1; // 適当な初期ベクトル

	if(k<2000) Gauss_Jordan(k,A,b,x);
	else       Gauss_Seidel(k,A,b,x);

	printf("%.9f\n",x[0]);

	return 0;
}
accuracy: 0.3
time_ms: 2340
memory_kb: 47716
final_rank: 14

code_snippet: #include<cmath>
#include<cstdio>
#include<vector>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int N_MAX=2500;

void Gauss_Jordan(int n,double A[N_MAX][N_MAX+1],const double *b,double *x){
	rep(i,n) A[i][n]=b[i];

	rep(i,n){
		int piv=i;
		for(int j=i;j<n;j++) if(abs(A[j][i])>abs(A[piv][i])) piv=j;
		rep(j,n+1) swap(A[i][j],A[piv][j]);

		for(int j=i+1;j<=n;j++) A[i][j]/=A[i][i];
		rep(j,n) if(i!=j) for(int k=i+1;k<=n;k++) A[j][k]-=A[j][i]*A[i][k];
	}

	rep(i,n) x[i]=A[i][n];
}

void Gauss_Seidel(int n,const double A[N_MAX][N_MAX+1],const double *b,double *x){
	rep(_,100){
		rep(i,n){
			double y=b[i];
			rep(j,n) if(j!=i) y-=A[i][j]*x[j];
			x[i]=y/A[i][i];
		}
	}
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	bool G[10][10]={};
	int deg[10]={};
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		G[u][v]=G[v][u]=true;
		deg[u]++;
		deg[v]++;
	}

	vector<int> V; // 訪問済みの頂点集合としてありえるもの全体
	rep(S,1<<n){
		if((S&1)==0) continue;

		bool vis[10]={true};
		int Q[10],head=0,tail=0;
		Q[tail++]=0;
		while(head<tail){
			int u=Q[head++];
			rep(v,n) if(G[u][v] && !vis[v] && (S>>v)&1) {
				vis[v]=true;
				Q[tail++]=v;
			}
		}

		bool ok=true;
		rep(u,n) if(((S>>u)&1)!=vis[u]) ok=false;
		if(ok) V.push_back(S);
	}

	int k=0;
	vector< pair<int,int> > T; // ありうる状態の全体 ( 訪問済みの頂点集合と今いる頂点のペア )
	int id[1<<10][10]; // T の逆写像
	rep(i,V.size()) rep(u,n) if((V[i]>>u)&1) {
		T.push_back(make_pair(V[i],u));
		id[V[i]][u]=k++;
	}

	// x[i] := 状態 i からスタートして全頂点を巡り終える時刻の期待値
	static double A[N_MAX][N_MAX+1],b[N_MAX],x[N_MAX];
	rep(i,k){
		int S=T[i].first,u=T[i].second;
		if(S!=(1<<n)-1){
			rep(v,n) if(G[u][v]) {
				int S2=S;
				if(((S>>v)&1)==0) S2|=1<<v;
				int j=id[S2][v];
				A[i][j]=-1.0/deg[u];
			}
			A[i][i]=1;
			b[i]=1;
		}
		else{ // 全頂点を巡り終えた状態
			A[i][i]=1;
		}
	}

	rep(u,k) x[u]=1; // 適当な初期ベクトル

	if(k<2000) Gauss_Jordan(k,A,b,x);
	else       Gauss_Seidel(k,A,b,x);

	printf("%.9f\n",x[0]);

	return 0;
}
accuracy: 0.1
time_ms: 2340
memory_kb: 47056
final_rank: 15