QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625836 | #7003. Rikka with Minimum Spanning Trees | ucup-team5071# | RE | 0ms | 0kb | C++20 | 1.3kb | 2024-10-09 21:20:31 | 2024-10-09 21:20:32 |
answer
#include <bits/stdc++.h>
using namespace std;
int solve()
{
int n,k,mod;cin>>n>>k>>mod;
vector<pair<int,int>> p(k);
for(int i=0;i<k;i++)cin>>p[i].first>>p[i].second;
auto count = [&](vector<int>a,int op){
for(int i=k-1;i>=0;i--){
if((op>>i&1)^(a[p[i].first]<a[p[i].second]))return 0;
if(op>>i&1)swap(a[p[i].first],a[p[i].second]);
}
return 1;
};
int ans=0;
auto add = [&](int &x,int y){
if((x+=y)>=mod)x-=mod;
};
for(int i=1;i<=n;i++){
vector<int> a(n+1);iota(a.begin(),a.end(),0);
for(int j=i+1;j<=n;j++){
swap(a[j-1],a[j]);
for(int z=0;z<(1<<k);z++)add(ans,count(a,z));
}
}
for(int i=1;i<=n;i++){
vector<int> a(n+1);iota(a.begin(),a.end(),0);
if(i>1)swap(a[i],a[i-1]);
for(int j=i-2;j>=1;j--){
swap(a[j+1],a[j]);
for(int z=0;z<(1<<k);z++)add(ans,count(a,z));
}
}
vector<int>a(n+1);iota(a.begin(),a.end(),0);
for(int z=0;z<(1<<k);z++)add(ans,count(a,z));
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;cin>>T;
while(T--)cout<<solve()<<"\n";
}
/*
4
4 0 998244353
4 1 998244353
1 2
4 3 998244353
1 2
2 3
1 2
4 6 998244353
1 2
2 3
1 2
3 4
2 3
1 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
1 2 100000 123456789 987654321