AT_abc232_c 题解
题目传送门
思路
由于
先用邻接矩阵存储图,设两个图分别为
AC CODE
#include<bits/stdc++.h>
using namespace std;
int read(){int x=0;char f=1,ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();return x*f;}
const int N=10;
bool a[N][N],b[N][N];
int n,m,p[N];
bool check(){
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
if(a[i][j]!=b[p[i]][p[j]])
return false;
return true;
}
int main(){
n=read(),m=read();
for(int i=1;i<=m;++i){
int u=read(),v=read();
a[u][v]=a[v][u]=true;
}
for(int i=1;i<=m;++i){
int u=read(),v=read();
b[u][v]=b[v][u]=true;
}
for(int i=1;i<=n;++i)
p[i]=i;
do{
if(check())
return printf("Yes\n"),0;
}while(next_permutation(p+1,p+n+1));
printf("No\n");
return 0;
}