QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#816649 | #6970. 地震后的幻想乡 | Kevin5307 | 100 ✓ | 8ms | 8556kb | C++23 | 2.0kb | 2024-12-16 16:04:30 | 2024-12-16 16:04:31 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
#define ld __float128
void die(string S){puts(S.c_str());exit(0);}
vector<longer> f[1<<10],g[1<<10];
vector<longer> pw[55];
int E[15][15];
int c[1<<10][1<<10];
vector<longer> add(vector<longer> A,vector<longer> B)
{
A.resize(max(sz(A),sz(B)));
for(int i=0;i<sz(B);i++) A[i]+=B[i];
return A;
}
vector<longer> mul(vector<longer> A,vector<longer> B)
{
vector<longer> ans(sz(A)+sz(B)-1);
for(int i=0;i<sz(A);i++)
for(int j=0;j<sz(B);j++)
ans[i+j]+=A[i]*B[j];
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
pw[0]={1};
for(int i=1;i<55;i++)
pw[i]=mul(pw[i-1],{1,-1});
int n,m;
cin>>n>>m;
while(m--)
{
int a,b;
cin>>a>>b;
a--;
b--;
E[a][b]=E[b][a]=1;
}
for(int i=0;i<n;i++)
{
f[(1<<i)]={0};
g[(1<<i)]={1};
}
for(int i=1;i<(1<<n);i++)
{
int r=(1<<n)-i-1;
for(int j=r;;j=(j-1)&r)
{
int p=__lg(i&(-i));
for(int a=0;a<n;a++) if(j>>a&1)
c[i][j]+=E[p][a];
c[i][j]+=c[i^(1<<p)][j];
if(!j) break;
}
}
for(int i=1;i<(1<<n);i++)
if(__builtin_popcount(i)>1)
{
int p=__lg(i&(-i));
for(int j=i;j;j=(j-1)&i)
if(j>>p&1) if(i!=j)
f[i]=add(f[i],mul(g[j],pw[c[i^j][j]]));
g[i]=f[i];
for(auto &x:g[i]) x=-x;
g[i][0]++;
}
ld ans=0;
for(int i=0;i<sz(f[(1<<n)-1]);i++)
ans+=(ld)(f[(1<<n)-1][i])/(i+1);
printf("%.6Lf\n",(long double)ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 1ms
memory: 4004kb
input:
2 1 2 1
output:
0.500000
result:
ok single line: '0.500000'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3964kb
input:
3 2 2 1 3 2
output:
0.666667
result:
ok single line: '0.666667'
Test #3:
score: 5
Accepted
time: 0ms
memory: 3960kb
input:
3 3 2 1 3 1 3 2
output:
0.500000
result:
ok single line: '0.500000'
Test #4:
score: 5
Accepted
time: 8ms
memory: 8092kb
input:
10 10 2 1 4 1 4 3 6 2 7 3 7 4 9 3 9 5 9 8 10 5
output:
0.881818
result:
ok single line: '0.881818'
Test #5:
score: 5
Accepted
time: 4ms
memory: 8340kb
input:
10 10 2 1 5 2 5 4 6 1 7 3 7 5 8 3 8 5 9 7 10 5
output:
0.872727
result:
ok single line: '0.872727'
Test #6:
score: 5
Accepted
time: 8ms
memory: 8092kb
input:
10 10 6 5 7 2 8 1 8 4 8 6 9 1 9 3 9 5 10 6 10 7
output:
0.863636
result:
ok single line: '0.863636'
Test #7:
score: 5
Accepted
time: 8ms
memory: 8372kb
input:
10 45 2 1 3 1 3 2 4 1 4 2 4 3 5 1 5 2 5 3 5 4 6 1 6 2 6 3 6 4 6 5 7 1 7 2 7 3 7 4 7 5 7 6 8 1 8 2 8 3 8 4 8 5 8 6 8 7 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9
output:
0.274864
result:
ok single line: '0.274864'
Test #8:
score: 5
Accepted
time: 2ms
memory: 6404kb
input:
9 36 2 1 3 1 3 2 4 1 4 2 4 3 5 1 5 2 5 3 5 4 6 1 6 2 6 3 6 4 6 5 7 1 7 2 7 3 7 4 7 5 7 6 8 1 8 2 8 3 8 4 8 5 8 6 8 7 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8
output:
0.294173
result:
ok single line: '0.294173'
Test #9:
score: 5
Accepted
time: 1ms
memory: 4092kb
input:
5 7 2 1 3 1 4 2 4 3 5 1 5 2 5 4
output:
0.545238
result:
ok single line: '0.545238'
Test #10:
score: 5
Accepted
time: 1ms
memory: 4216kb
input:
5 7 3 2 4 1 4 2 4 3 5 1 5 3 5 4
output:
0.561905
result:
ok single line: '0.561905'
Test #11:
score: 5
Accepted
time: 1ms
memory: 3944kb
input:
5 8 3 1 4 1 4 2 4 3 5 1 5 2 5 3 5 4
output:
0.511905
result:
ok single line: '0.511905'
Test #12:
score: 5
Accepted
time: 1ms
memory: 3948kb
input:
5 8 3 1 3 2 4 1 4 2 5 1 5 2 5 3 5 4
output:
0.492063
result:
ok single line: '0.492063'
Test #13:
score: 5
Accepted
time: 2ms
memory: 4892kb
input:
8 15 3 1 4 1 4 2 4 3 5 1 5 2 6 2 6 3 7 1 7 4 8 1 8 3 8 4 8 6 8 7
output:
0.558508
result:
ok single line: '0.558508'
Test #14:
score: 5
Accepted
time: 0ms
memory: 4832kb
input:
8 15 2 1 3 1 5 1 5 2 5 4 6 1 6 2 7 1 7 2 7 3 7 5 8 2 8 3 8 4 8 5
output:
0.570480
result:
ok single line: '0.570480'
Test #15:
score: 5
Accepted
time: 2ms
memory: 5020kb
input:
8 18 3 1 4 3 5 4 6 2 6 4 6 5 7 1 7 2 7 3 7 4 7 5 8 1 8 2 8 3 8 4 8 5 8 6 8 7
output:
0.482269
result:
ok single line: '0.482269'
Test #16:
score: 5
Accepted
time: 2ms
memory: 5020kb
input:
8 18 2 1 3 2 4 2 4 3 5 2 5 3 5 4 6 2 6 3 7 1 7 2 7 3 7 4 7 5 7 6 8 1 8 3 8 5
output:
0.489007
result:
ok single line: '0.489007'
Test #17:
score: 5
Accepted
time: 3ms
memory: 8188kb
input:
10 22 2 1 4 1 5 1 5 2 6 1 6 2 6 5 7 1 7 2 7 4 7 6 8 3 8 4 8 6 9 3 9 4 9 7 10 1 10 2 10 4 10 6 10 8
output:
0.548805
result:
ok single line: '0.548805'
Test #18:
score: 5
Accepted
time: 6ms
memory: 8556kb
input:
10 22 3 1 3 2 4 3 5 3 6 2 6 3 6 4 7 1 7 2 7 4 7 5 7 6 8 4 9 1 9 3 9 4 9 6 10 1 10 2 10 3 10 7 10 8
output:
0.559280
result:
ok single line: '0.559280'
Test #19:
score: 5
Accepted
time: 5ms
memory: 8468kb
input:
10 25 3 1 4 1 5 2 5 3 5 4 6 1 6 4 6 5 7 2 7 4 8 1 8 3 8 5 8 7 9 1 9 2 9 4 9 6 9 7 10 2 10 3 10 6 10 7 10 8 10 9
output:
0.447754
result:
ok single line: '0.447754'
Test #20:
score: 5
Accepted
time: 3ms
memory: 8368kb
input:
10 25 3 2 4 3 5 1 5 2 5 4 6 3 6 4 7 1 7 5 8 1 8 3 8 4 8 6 8 7 9 1 9 2 9 3 9 4 9 6 9 7 10 2 10 4 10 5 10 6 10 8
output:
0.452142
result:
ok single line: '0.452142'