Submission #579376

#TimeUsernameProblemLanguageResultExecution timeMemory
579376amunduzbaevAmusement Park (CEOI19_amusementpark)C++17
19 / 100
3019 ms52440 KiB
#include "bits/stdc++.h" using namespace std; #define ar array typedef int64_t ll; //~ #define int ll const int N = 20; const int P = 167; const int mod = 119 << 23 | 1; vector<int> edges[N], qwe[N]; int used[N], is[N][N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n, m; cin>>n>>m; vector<ar<int, 2>> e(m); for(int i=0;i<m;i++){ cin>>e[i][0]>>e[i][1]; edges[e[i][0]].push_back(e[i][1]); edges[e[i][1]].push_back(e[i][0]); is[e[i][0]][e[i][1]] = 1; } for(int i=1;i<=n;i++) sort(edges[i].begin(), edges[i].end()); vector<int> p(n); iota(p.begin(), p.end(), 1); set<vector<int>> ss; int res = 0; do{ memset(used, 0, sizeof used); int cnt = 0; for(auto u : p){ qwe[u].clear(); for(auto x : edges[u]){ if(used[x]) continue; qwe[u].push_back(x); if(!is[u][x]) cnt++; } used[u] = 1; } memset(used, 0, sizeof used); vector<int> t; function<void(int)> dfs = [&](int u){ used[u] = 1; for(auto x : qwe[u]){ if(used[x]) continue; dfs(x); } t.push_back(u); }; for(int i=1;i<=n;i++){ if(!used[i]) dfs(i); } reverse(t.begin(), t.end()); //~ int hh = 0; //~ for(auto x : t){ //~ hh = (hh * 1ll * P + x) % mod; //~ } if(!ss.count(t)){ ss.insert(t); res = (res + cnt) % mod; } }while(next_permutation(p.begin(), p.end())); cout<<res<<"\n"; }
#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...