#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,k,n) for (int i = (k); i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
// using P = pair<ll,ll>;
const ll INF = (ll)1e18;
// const int INF = (int)1e9+7;
template<typename T>
void chmin(T &a, T b) { a = min(a, b); }
template<typename T>
void chmax(T &a, T b) { a = max(a, b); }
using Graph = vector<set<int>>;
void print(vector<int> v) {
rep(i,v.size()) cout << v[i] << ' ';
cout << endl;
}
void solve() {
int n, m;
cin >> n >> m;
Graph takahashi(n), aoki(n);
rep(i,m) {
int a, b;
cin >> a >> b;
a--, b--;
takahashi[a].insert(b);
takahashi[b].insert(a);
}
rep(i,m) {
int a, b;
cin >> a >> b;
a--, b--;
aoki[a].insert(b);
aoki[b].insert(a);
}
vector<int> perm;
rep(i,n) perm.push_back(i);
do {
bool ok = true;
rep(i,n) {
int ai = perm[i]; // 高橋にとっての i が aoki にとっての ai
if (takahashi[i].size() != aoki[ai].size()) {
ok = false;
break;
}
for (int ti : takahashi[i]) {
int aitem = perm[ti];
if (aoki[ai].find(aitem) == aoki[ai].end()) {
ok = false;
break;
}
}
}
if (ok) {
cout << "Yes" << endl;
return;
}
} while (next_permutation(all(perm)));
cout << "No" << endl;
}
int main() {
solve();
return 0;
}
./Main.cpp: In function ‘void print(std::vector<int>)’:
./Main.cpp:4:36: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
4 | #define rep(i,n) for (int i = 0; i < (n); ++i)
| ^
./Main.cpp:21:5: note: in expansion of macro ‘rep’
21 | rep(i,v.size()) cout << v[i] << ' ';
| ^~~