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;
using ll = long long;
const int mod = 998244353;
int add(int a, int b) {
a += b;
if (a >= mod) a -= mod;
return a;
}
int mul(int a, int b) {
return (ll)a * b % mod;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> fac(n + 1);
fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = mul(fac[i - 1], i);
}
vector<vector<int>> adj(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
adj[a].push_back(b);
}
vector cnt(1 << n, vector<int>(n));
for (int i = 0; i < (1 << n); i++) {
for (int j = 0; j < n; j++) {
for (int k : adj[j]) {
if (i >> k & 1) {
cnt[i][j]++;
}
}
}
}
vector<int> dp(1 << n);
for (int i = 0; i < (1 << n); i++) {
for (int j = 0; j < n; j++) {
if (i >> j & 1) {
dp[i] = add(dp[i], add(dp[i - (1 << j)], mul(fac[__builtin_popcount(i) - 1], cnt[i - (1 << j)][j])));
}
}
}
cout << dp[(1 << n) - 1];
return 6/22;
}
# | 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... |