# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
697106 | Alihan_8 | Amusement Park (CEOI19_amusementpark) | C++17 | 3061 ms | 17248 KiB |
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>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m; cin >> n >> m;
vector <int> a(m), b(m);
for ( int i = 0; i < m; i++ ){
cin >> a[i] >> b[i];
a[i]--, b[i]--;
}
const int Mod = 998244353;
vector <int> p(n);
iota(all(p), 0);
set <int> st;
do{
vector <int> g[n], pos(n);
for ( int i = 0; i < n; i++ ) pos[p[i]] = i;
int rev = 0, mask = 0;
for ( int i = 0; i < m; i++ ){
if ( pos[a[i]] > pos[b[i]] ){
g[b[i]].pb(a[i]);
mask |= 1ll << i;
}
else g[a[i]].pb(b[i]);
}
vector <int> used(n);
function <bool(int)> dfs = [&](int x){
used[x] = true;
for ( auto to: g[x] ){
if ( !used[to] ){
if ( dfs(to) ) return true;
}
else if ( used[to] == 1 ) return true;
}
used[x] = 2;
return false;
};
bool flag = true;
for ( int i = 0; i < n; i++ ){
if ( !used[i] and dfs(i) ){
flag = false;
break;
}
}
if ( flag ) st.insert(mask);
} while ( next_permutation(all(p)) );
int cnt = 0;
auto f = [&](int x){
return __builtin_popcountll(x);
};
for ( auto i: st ) cnt = (cnt+f(i))%Mod;
cout << cnt;
cout << '\n';
}
Compilation message (stderr)
# | 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... |