#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 40, MAXM = 1e3 + 10;
pair<int,int>M[MAXM];
int tmp[MAXN];
int n, m;
ll ans[MAXN];
void calculate(vector<bool> &cur){
for (int i = 0; i < n; i++){
tmp[i] = i + 1;
}
for (int i = 0; i < m; i++){
if (cur[tmp[M[i].first-1]-1] && !cur[tmp[M[i].second-1]-1]){
swap(tmp[M[i].first-1], tmp[M[i].second-1]);
}
}
int last = -1, cnt = 0;
for (int i = 0; i < n; i++){
if (cur[tmp[i]-1]){
cnt++;
if (last != -1 && last != i - 1){
return;
}
last = i;
}
}
ans[cnt]++;
if (ans[cnt] >= 2) ans[cnt] -= 2;
return;
}
void gen(vector<bool> &cur){
if (cur.size() == n){
calculate(cur);
return;
}
cur.push_back(false);
gen(cur);
cur.pop_back();
cur.push_back(true);
gen(cur);
cur.pop_back();
}
void solve(int n, int m){
vector<bool>cur;
gen(cur);
for (int i = 1; i <= n; i++){
cout << ans[i] << " ";
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++){
cin >> M[i].first >> M[i].second;
}
solve(n,m);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 40, MAXM = 1e3 + 10; pair<int,int>M[MAXM]; int tmp[MAXN]; int n, m; ll ans[MAXN]; void calculate(vector<bool> &cur){ for (int i = 0; i < n; i++){ tmp[i] = i + 1; } for (int i = 0; i < m; i++){ if (cur[tmp[M[i].first-1]-1] && !cur[tmp[M[i].second-1]-1]){ swap(tmp[M[i].first-1], tmp[M[i].second-1]); } } int last = -1, cnt = 0; for (int i = 0; i < n; i++){ if (cur[tmp[i]-1]){ cnt++; if (last != -1 && last != i - 1){ return; } last = i; } } ans[cnt]++; if (ans[cnt] >= 2) ans[cnt] -= 2; return; } void gen(vector<bool> &cur){ if (cur.size() == n){ calculate(cur); return; } cur.push_back(false); gen(cur); cur.pop_back(); cur.push_back(true); gen(cur); cur.pop_back(); } void solve(int n, int m){ vector<bool>cur; gen(cur); for (int i = 1; i <= n; i++){ cout << ans[i] << " "; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < m; i++){ cin >> M[i].first >> M[i].second; } solve(n,m); } |
English