Submission #1039387

#TimeUsernameProblemLanguageResultExecution timeMemory
1039387ef10Amusement Park (CEOI19_amusementpark)C++17
0 / 100
0 ms440 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; #define LL long long #define MODULE 998244353 int N,M; vector<int> adj[20]; LL dp[1<<18][20]; LL exp(LL a, LL b) { if (a==0) return 0; if (b == 0) return 1; LL ret = exp(a, b/2); ret = ret * ret; ret %= MODULE; if (b % 2) { ret *= a; ret %= MODULE; } return ret; } LL inv(LL x) { return exp(x, MODULE-2); } int main() { cin >> N >> M; for (int i = 0; i < M; i++) { int a,b; cin >> a >> b; a--;b--; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 0; i < N; i++) { dp[1<<i][i]=1; } for (int i = 0; i < (1<<N); i++) { for (int j = 0; j < N; j++) { if (dp[i][j] == 0) continue; for (auto n : adj[j]) { if (i & (1<<n)) continue; dp[i | (1<<n)][n] += dp[i][j]; dp[i | (1<<n)][n] %= MODULE; } } } LL res = 0; for (int i = 0; i < N; i++) { res += dp[(1<<N)-1][i]; res %= MODULE; } //cout << res << endl; res *= M; res %= MODULE; res *= inv(2); res %= MODULE; cout << res << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...