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 endl '\n'
using namespace std;
const int MAXN = 12, MAXM = 200;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, m;
int from[MAXM], to[MAXM];
void read()
{
cin >> n >> m;
for (int i = 1; i <= m; ++ i)
cin >> from[i] >> to[i];
}
int order[MAXN], used[MAXN], visited[MAXN], in_cycle[MAXN]; /// na koq poziciq e i
long long ans = 0, imp = 0;
const long long mod = 998244353;
set < vector < int > > mp;
vector < int > g[MAXN];
void dfs(int beg)
{
visited[beg] = 1;
in_cycle[beg] = 1;
for (auto nb: g[beg])
{
if(!visited[nb])dfs(nb);
else if(in_cycle[nb])imp = 1;
}
in_cycle[beg] = 0;
}
void check()
{
for (int i = 1; i <= n; ++ i)
{
g[i].clear();
visited[i] = 0;
in_cycle[i] = 0;
}
vector < int > u;
int cnt = 0;
for (int i = 1; i <= m; ++ i)
{
if(order[from[i]] > order[to[i]])
{
u.push_back(0);
g[from[i]].push_back(to[i]);
}
else
{
cnt ++;
u.push_back(1);
g[to[i]].push_back(from[i]);
}
}
if(mp.find(u) != mp.end())return;
mp.insert(u);
imp = 0;
for (int i = 1; i <= n; ++ i)
{
if(visited[order[i]])continue;
dfs(visited[order[i]]);
}
if(imp)return;
ans += cnt;
ans %= mod;
}
void gen(int pos)
{
if(pos > n)
{
check();
return;
}
for (int i = 1; i <= n; ++ i)
{
if(used[i])continue;
order[pos] = i;
used[i] = 1;
gen(pos+1);
used[i] = 0;
}
}
int main()
{
speed();
read();
gen(1);
cout << ans << endl;
return 0;
}
# | 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... |