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>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 998244353
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#define TASKNAME "amusepark"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 3e2 + 9;
ii edge[MAXN];
int n,m,ans=0;
int pos[MAXN];
const ii mod = {1e9+7,998244353};
const ii base = {311,113};
ii operator + (const ii &a,const ii &b){
    return {(a.fi + b.fi) % mod.fi, (a.se + b.se) % mod.se};
}
ii operator - (const ii &a,const ii &b){
    return {((a.se - b.fi) % mod.fi + mod.fi)%mod.fi,((a.se - b.fi) % mod.se + mod.se)%mod.se};
}
ii operator * (const ii &a,const ii &b){
    return {(a.fi * b.fi) % mod.fi, (a.se * b.se) % mod.se};
}
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        if (hash1 != hash2) {
            return hash1 ^ hash2;
        }
        // If hash1 == hash2, their XOR is zero.
          return hash1;
    }
};
unordered_map<ii,bool,hash_pair> hashcode;
main()
{
    fast;
    // freopen(TASKNAME".inp","r",stdin);
    // freopen(TASKNAME".out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>edge[i].fi>>edge[i].se;
    }
    int permutation[15];
    string s;
    iota(permutation+1,permutation+1+n,1);
    do{
        for(int i=1;i<=n;i++){
            pos[permutation[i]] = i;
        }
        int cost = 0;
        ii code = {0,0};
        for(int i=1;i<=m;i++){
            if (pos[edge[i].fi] > pos[edge[i].se]) {
                cost++;
                code = (code * base + ii(3,2));
            }
            else{
                code = (code * base + ii(2,1));
            }
        }
        if (hashcode[code] == 0){
            ans = (ans + cost) % MOD;
            hashcode[code] = 1;
        }
    }while(next_permutation(permutation+1,permutation+1+n));
    cout<<ans<<endl;
}
Compilation message (stderr)
amusementpark.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   52 | main()
      | ^~~~| # | 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... |