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>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N = 1e5 + 5;
set <long long> s;
pair <int, int> ed[N];
int pos[N];
int n,m;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> ed[i].fi >> ed[i].se;
}
if (n > 10)
return 0;
int ans = 0;
vector <int> id(n, 0); iota(id.begin(), id.end(), 1);
do {
for (int i = 0; i < n; i++)
pos[id[i]] = i;
long long res = 0;
int cnt = 0;
for (int i = 0; i < m; i++) {
int u = ed[i].fi;
int v = ed[i].se;
if (pos[u] > pos[v]) {
cnt++;
res |= (1LL << i);
}
}
if (s.find(res) == s.end()) {
ans += cnt;
s.insert(res);
}
} while (next_permutation(id.begin(), id.end()));
cout << ans;
return 0;
}
# | 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... |