QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#218851 | #7150. Random spanning tree | SolitaryDream# | AC ✓ | 20ms | 4688kb | C++17 | 1.7kb | 2023-10-18 19:19:19 | 2023-10-18 19:19:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
typedef __int128 ll;
const int N=30;
int n,m;
vector<int> link(vector<int> a,int x,int y) {
if(a[x]>a[y]) swap(x,y);
int c=a[y];
FOR(i,0,n-1) {
if(a[i]==c) a[i]=a[x];
else if(a[i]>c) a[i]--;
}
return a;
}
map<vector<int>,pair<ll,ll>> f[N];
void pt(ll x) {
vector<int> v;
while(x) v.push_back(x%10),x/=10;
while(v.size()) cout << v.back(),v.pop_back();
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
{
vector<int> a(n);
FOR(i,0,n-1) a[i]=i;
f[0][a]={0,1};
}
vector<pair<int,int>> E;
FOR(i,1,m) {
int x,y;
cin >> x >> y;
--x;
--y;
E.push_back({x,y});
}
FOR(i,1,m) {
// cerr << f[i-1].size() << endl;
for(auto [a,v]: f[i-1]) {
// pt(v.second);
// cout << endl;
int k=0;
for(auto [x,y]: E) {
if(a[x]==a[y]) ++k;
}
if(i<=k) {
f[i][a].first+=v.first*(k-i+1);
f[i][a].second+=v.second*(k-i+1);
}
for(auto [x,y]: E) if(a[x]!=a[y]) {
auto b=link(a,x,y);
f[i][b].first+=v.first+i*v.second;
f[i][b].second+=v.second;
}
}
}
auto ans=f[m].begin()->second;
ans.second*=m+1;
ll g=__gcd(ans.first,ans.second);
ans.first/=g;
ans.second/=g;
pt(ans.first);
cout << '/';
pt(ans.second);
cout << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3444kb
input:
3 2 1 2 2 3
output:
1/1
result:
ok single line: '1/1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
3 3 1 2 2 3 3 1
output:
3/4
result:
ok single line: '3/4'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
2 1 2 1
output:
1/2
result:
ok single line: '1/2'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
2 1 1 2
output:
1/2
result:
ok single line: '1/2'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3432kb
input:
2 1 1 2
output:
1/2
result:
ok single line: '1/2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3416kb
input:
2 1 1 2
output:
1/2
result:
ok single line: '1/2'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
2 1 1 2
output:
1/2
result:
ok single line: '1/2'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
2 1 1 2
output:
1/2
result:
ok single line: '1/2'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3432kb
input:
2 1 1 2
output:
1/2
result:
ok single line: '1/2'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3436kb
input:
2 1 1 2
output:
1/2
result:
ok single line: '1/2'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
2 1 1 2
output:
1/2
result:
ok single line: '1/2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
2 1 1 2
output:
1/2
result:
ok single line: '1/2'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
3 2 2 1 3 2
output:
1/1
result:
ok single line: '1/1'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
3 3 2 1 1 3 3 2
output:
3/4
result:
ok single line: '3/4'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
3 2 2 3 2 1
output:
1/1
result:
ok single line: '1/1'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
3 2 2 3 1 3
output:
1/1
result:
ok single line: '1/1'
Test #17:
score: 0
Accepted
time: 1ms
memory: 3484kb
input:
3 3 1 3 3 2 2 1
output:
3/4
result:
ok single line: '3/4'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3424kb
input:
3 2 2 3 1 3
output:
1/1
result:
ok single line: '1/1'
Test #19:
score: 0
Accepted
time: 1ms
memory: 3456kb
input:
3 3 2 3 2 1 3 1
output:
3/4
result:
ok single line: '3/4'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3428kb
input:
3 3 2 1 2 3 1 3
output:
3/4
result:
ok single line: '3/4'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3428kb
input:
3 2 1 2 2 3
output:
1/1
result:
ok single line: '1/1'
Test #22:
score: 0
Accepted
time: 1ms
memory: 3440kb
input:
3 2 1 3 2 3
output:
1/1
result:
ok single line: '1/1'
Test #23:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
4 3 2 1 1 3 2 4
output:
3/2
result:
ok single line: '3/2'
Test #24:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
4 6 1 4 4 3 1 2 2 3 1 3 2 4
output:
31/35
result:
ok single line: '31/35'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
4 5 2 4 2 3 4 3 3 1 1 4
output:
31/30
result:
ok single line: '31/30'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
4 3 1 3 4 1 1 2
output:
3/2
result:
ok single line: '3/2'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3424kb
input:
4 6 2 1 4 3 1 3 3 2 2 4 4 1
output:
31/35
result:
ok single line: '31/35'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
4 5 3 1 3 2 4 3 4 2 4 1
output:
31/30
result:
ok single line: '31/30'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
4 4 4 3 1 2 4 2 4 1
output:
5/4
result:
ok single line: '5/4'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
4 6 4 2 1 2 2 3 3 4 1 4 3 1
output:
31/35
result:
ok single line: '31/35'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
4 5 4 3 1 2 3 1 2 3 1 4
output:
31/30
result:
ok single line: '31/30'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
4 5 4 2 1 3 1 2 2 3 1 4
output:
31/30
result:
ok single line: '31/30'
Test #33:
score: 0
Accepted
time: 1ms
memory: 3496kb
input:
5 5 1 4 4 3 5 2 4 5 3 1
output:
7/4
result:
ok single line: '7/4'
Test #34:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
5 9 3 4 2 4 3 1 5 2 1 4 5 3 2 3 1 5 5 4
output:
893/840
result:
ok single line: '893/840'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3476kb
input:
5 5 5 2 5 1 1 2 3 1 3 4
output:
7/4
result:
ok single line: '7/4'
Test #36:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
5 7 3 1 5 1 4 1 4 2 5 3 1 2 3 4
output:
1111/840
result:
ok single line: '1111/840'
Test #37:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
5 10 5 3 2 3 4 5 1 3 2 1 5 2 1 5 4 2 4 1 4 3
output:
893/924
result:
ok single line: '893/924'
Test #38:
score: 0
Accepted
time: 1ms
memory: 3428kb
input:
5 4 1 2 1 4 1 3 5 4
output:
2/1
result:
ok single line: '2/1'
Test #39:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
5 7 5 4 5 1 1 3 3 5 5 2 3 4 2 4
output:
1111/840
result:
ok single line: '1111/840'
Test #40:
score: 0
Accepted
time: 1ms
memory: 3456kb
input:
5 9 4 5 1 3 4 3 1 5 2 4 5 3 1 2 4 1 2 5
output:
893/840
result:
ok single line: '893/840'
Test #41:
score: 0
Accepted
time: 1ms
memory: 3420kb
input:
5 5 2 1 5 3 5 1 2 4 5 2
output:
7/4
result:
ok single line: '7/4'
Test #42:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
5 4 3 4 1 3 2 3 5 1
output:
2/1
result:
ok single line: '2/1'
Test #43:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
6 15 1 2 4 1 2 3 4 3 5 3 3 1 5 2 4 2 1 5 4 5 6 2 6 4 1 6 3 6 6 5
output:
278/273
result:
ok single line: '278/273'
Test #44:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
6 14 6 3 2 3 4 6 1 6 6 2 6 5 4 2 4 1 5 3 5 2 1 3 4 3 1 5 2 1
output:
4448/4095
result:
ok single line: '4448/4095'
Test #45:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
6 5 1 5 4 2 3 5 4 3 3 6
output:
5/2
result:
ok single line: '5/2'
Test #46:
score: 0
Accepted
time: 1ms
memory: 3504kb
input:
6 10 4 2 4 3 4 6 5 1 3 2 3 5 2 1 6 1 6 3 6 2
output:
453/308
result:
ok single line: '453/308'
Test #47:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
6 12 5 3 4 1 2 4 3 1 5 6 3 4 2 6 6 4 2 3 1 2 1 6 5 2
output:
29881/24024
result:
ok single line: '29881/24024'
Test #48:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
6 11 3 5 4 3 4 6 4 5 2 4 6 2 6 5 1 5 2 5 2 3 4 1
output:
1733/1260
result:
ok single line: '1733/1260'
Test #49:
score: 0
Accepted
time: 1ms
memory: 3484kb
input:
6 13 4 1 5 3 2 4 4 6 5 2 2 3 6 2 6 3 4 3 1 5 6 1 2 1 1 3
output:
10799/9240
result:
ok single line: '10799/9240'
Test #50:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
6 14 3 5 2 3 6 3 5 1 3 1 2 1 2 5 2 6 6 5 4 3 4 2 4 1 5 4 1 6
output:
4448/4095
result:
ok single line: '4448/4095'
Test #51:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
6 5 2 6 3 2 4 6 6 5 2 1
output:
5/2
result:
ok single line: '5/2'
Test #52:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
6 13 5 3 1 4 6 2 3 1 5 6 3 4 2 4 5 1 3 2 2 1 3 6 4 6 5 2
output:
34751/30030
result:
ok single line: '34751/30030'
Test #53:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
7 10 1 7 5 1 2 3 1 6 3 7 4 5 7 2 5 6 1 2 5 3
output:
5263/2520
result:
ok single line: '5263/2520'
Test #54:
score: 0
Accepted
time: 7ms
memory: 3900kb
input:
7 21 1 4 5 4 2 1 3 7 3 2 1 7 3 4 5 7 2 7 1 5 3 5 2 5 6 3 5 6 6 7 4 2 3 1 4 7 6 4 6 1 6 2
output:
30739/29172
result:
ok single line: '30739/29172'
Test #55:
score: 0
Accepted
time: 3ms
memory: 3608kb
input:
7 16 7 3 7 1 7 6 6 2 6 5 3 6 1 3 7 4 6 1 2 4 2 5 3 5 6 4 3 2 1 4 4 3
output:
1049207/765765
result:
ok single line: '1049207/765765'
Test #56:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
7 10 2 3 5 4 7 1 2 1 2 5 5 1 3 5 1 6 2 6 7 5
output:
89/42
result:
ok single line: '89/42'
Test #57:
score: 0
Accepted
time: 7ms
memory: 3836kb
input:
7 21 7 5 3 7 3 4 4 6 7 6 3 6 2 4 5 1 2 1 3 5 4 5 3 1 2 7 6 5 4 7 1 7 2 6 6 1 5 2 1 4 2 3
output:
30739/29172
result:
ok single line: '30739/29172'
Test #58:
score: 0
Accepted
time: 3ms
memory: 3664kb
input:
7 16 1 2 6 7 3 5 3 7 3 4 7 2 4 6 2 5 1 4 3 1 4 5 6 2 2 4 6 3 5 6 7 4
output:
16668527/12252240
result:
ok single line: '16668527/12252240'
Test #59:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
7 11 2 1 5 2 7 3 5 6 6 2 4 1 3 1 3 4 1 6 2 7 4 2
output:
7493/3960
result:
ok single line: '7493/3960'
Test #60:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
7 6 4 1 3 4 6 1 2 7 5 2 4 2
output:
3/1
result:
ok single line: '3/1'
Test #61:
score: 0
Accepted
time: 3ms
memory: 3608kb
input:
7 16 7 1 1 3 2 6 5 3 4 1 6 7 2 7 2 5 6 3 6 1 4 7 3 7 4 3 6 4 2 3 6 5
output:
1049207/765765
result:
ok single line: '1049207/765765'
Test #62:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
7 8 2 3 6 3 7 4 3 1 4 5 4 1 5 1 7 3
output:
1039/420
result:
ok single line: '1039/420'
Test #63:
score: 0
Accepted
time: 16ms
memory: 4348kb
input:
8 21 8 7 1 8 6 7 4 3 2 1 8 6 3 1 4 6 5 1 8 4 4 7 3 8 5 8 2 6 2 7 6 1 7 3 3 5 4 1 4 2 3 2
output:
110647451/77597520
result:
ok single line: '110647451/77597520'
Test #64:
score: 0
Accepted
time: 11ms
memory: 4232kb
input:
8 20 8 4 6 2 3 8 7 4 2 3 5 1 6 8 6 7 2 1 4 3 5 7 6 5 2 5 2 7 6 1 8 7 4 1 2 8 7 3 5 4
output:
342183313/232792560
result:
ok single line: '342183313/232792560'
Test #65:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
8 11 2 6 1 8 5 1 6 3 2 4 8 3 5 8 2 8 2 7 6 1 1 7
output:
1549/616
result:
ok single line: '1549/616'
Test #66:
score: 0
Accepted
time: 20ms
memory: 4688kb
input:
8 23 3 8 1 7 1 8 1 4 4 6 8 7 5 6 6 8 7 4 6 7 3 7 2 6 3 5 1 6 8 4 2 5 6 3 7 5 1 2 5 4 2 8 3 1 7 2
output:
22574459/17383860
result:
ok single line: '22574459/17383860'
Test #67:
score: 0
Accepted
time: 4ms
memory: 3704kb
input:
8 14 4 3 4 2 5 8 4 8 6 1 6 3 8 3 5 2 7 1 6 7 7 3 5 6 3 1 7 8
output:
367811/180180
result:
ok single line: '367811/180180'
Test #68:
score: 0
Accepted
time: 2ms
memory: 3592kb
input:
8 13 5 6 6 1 3 2 2 1 8 2 2 6 2 5 5 3 7 3 5 4 4 6 1 5 1 7
output:
273571/120120
result:
ok single line: '273571/120120'
Test #69:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
8 8 1 3 6 4 7 3 8 6 5 4 1 8 2 1 5 3
output:
22/7
result:
ok single line: '22/7'
Test #70:
score: 0
Accepted
time: 13ms
memory: 4324kb
input:
8 21 4 2 5 3 7 6 8 4 2 3 1 6 1 8 3 7 2 5 8 7 6 8 5 4 8 2 1 4 5 8 6 4 5 1 4 3 4 7 2 7 7 1
output:
11782289/8314020
result:
ok single line: '11782289/8314020'
Test #71:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
8 11 4 3 2 5 1 2 4 8 8 1 4 2 6 1 7 3 2 8 7 8 1 3
output:
6499/2520
result:
ok single line: '6499/2520'
Test #72:
score: 0
Accepted
time: 5ms
memory: 3756kb
input:
8 15 6 5 7 6 4 6 4 2 5 7 4 8 8 2 8 5 3 1 4 1 7 3 8 3 7 1 3 5 5 4
output:
115279/60060
result:
ok single line: '115279/60060'
Extra Test:
score: 0
Extra Test Passed