This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=11, mx=1e3+5, mod=998244353, mod2=1e9+7;
ll n, m, a[mx], b[mx], res, pw[mx];
set<ll> s;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
pw[0]=1;
for (int i=1; i<=m; i++) pw[i]=(pw[i-1]*2)%mod2;
for (int i=1; i<=m; i++) cin>>a[i]>>b[i];
vector<int> v;
for (int i=1; i<=n; i++) v.push_back(i);
do
{
ll sm=0, cnt=0;
for (int i=1; i<=m; i++) if (v[a[i]-1]>v[b[i]-1]) cnt++, sm=(sm+pw[i])%mod2;
if (s.find(sm)==s.end()) res=(res+cnt)%mod, s.insert(sm);
} while (next_permutation(v.begin(), v.end()));
cout<<res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |