Submission #1114075

#TimeUsernameProblemLanguageResultExecution timeMemory
1114075n3rm1nAmusement Park (CEOI19_amusementpark)C++17
0 / 100
1 ms336 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const int MAXN = 20; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int n, m; int from[MAXN], to[MAXN]; 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; 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(); int cnt = 0; for (int i = 1; i <= m; ++ i) { if(order[from[i]] > order[to[i]]) g[from[i]].push_back(to[i]); else { cnt ++; g[to[i]].push_back(from[i]); } } memset(visited, 0, sizeof(visited)); memset(in_cycle, 0, sizeof(in_cycle)); 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 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...