??透傎愵}目講解_Two Graphs( unordered_map)
// https://ac.nowcoder.com/acm/contest/20322/D
#include "stdafx.h"
//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
?#include <vector>
?#include <unordered_map>
using namespace std;
int n,m1,m2,ans;
int f[10];
int e1[10][10],e2[10][10];
?char edge[32][2]={
1 ,2,
1 ,3,
4 ,1,
4 ,2,
4, 3
};
?
int main(){
n=4,m1=2,m2=3;
? ?// while(std::cin>>n>>m1>>m2){
? ? ? ? memset(e1,0,sizeof(e1));
? ? ? ? memset(e2,0,sizeof(e2));
std::unordered_map<int,int>m;
? ? ? ? ans=0;
? ? ? ? for(int i=1,x,y;i<=m1;i++){
? ? ? ? ? ?// cin>>x>>y;
x=edge[i-1][0];
y=edge[i-1][1];
? ? ? ? ? ? e1[x][y]=e1[y][x]=1;
? ? ? ? }
? ? ? ? for(int i=1,x,y;i<=m2;i++){
? ? ? ? ? ?// cin>>x>>y;
x=edge[m1+i-1][0];
y=edge[m1+i-1][1];
? ? ? ? ? ? e2[x][y]=e2[y][x]=i;
? ? ? ? }
? ? ? ? for(int i=1;i<=n;i++)f[i]=i;
? ? ? ? do{
? ? ? ? ? ? int flag=1,v=0;
? ? ? ? ? ? for(int i=1;i<=n;i++){
? ? ? ? ? ? ? ? for(int j=1;j<=n;j++){
? ? ? ? ? ? ? ? ? ? if(e1[i][j]){
if(!e2[f[i]][f[j]]){flag=0;break;}
// cout<<endl<<"before? "<<v<<"? e2[f[i]][f[j]]=? "<<e2[f[i]][f[j]]<<endl;
? ? ? ? ? ? ? ? ? ? ? ? v|=1<<e2[f[i]][f[j]];
// cout<<"After? "<<v<<endl;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
if(!flag)break;
? ? ? ? ? ? }
? ? ? ? ? ? if(flag&&m[v]==0){
ans++,m[v]=1;
cout<<v<<endl;
}
? ? ? ? }while(std::next_permutation(f+1,f+n+1));
? ? ? ? printf("%d\n",ans);
? ?// }
? ? return 0;
}