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;
typedef long long ll;
ll MOD = 998244353;
int main() {
ll n, m;
cin >> n >> m;
vector<vector<ll> > adj(n);
for (ll i = 0; i < m; i++) {
ll a, b;
cin >> a >> b;
a--;b--;
adj[a].push_back(b);
}
vector<pair<ll, ll> > dp(1<<n, {0, 0});
dp[0]={1, 0};
for (ll i = 0; i < n; i++) dp[(1 << i)] = {1, 0};
for (ll i = 1; i < (1<<n); i++) {
// cout << i << dp[i].first << dp[i].second << endl;
for (ll ne = 0; ne < n; ne++) {
if ((1 << ne) & i) continue;
ll c = 0;
for (auto val: adj[ne]) {
if ((1 << val) & i) {
c++;
}
}
dp[i^(1 << ne)].second=((dp[i^(1 << ne)].second)%MOD+((dp[i].second)%MOD)+(dp[i].first*c)%MOD)%MOD;
if (c!=0)dp[i^(1 << ne)].first=(dp[i^(1 << ne)].first+dp[i].first)%MOD;
// cout << i<<(ne) << dp[i^(1 << ne)].second << endl;
}
}
cout << dp[(1<<n)-1].first << endl;
}
# | 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... |