自定义wordpress的字体,暴疯团队seo课程,怎么修改网站关键词,张家界seo【洛谷】AT_abc371_c [ABC371C] Make Isomorphic 的题解
洛谷传送门
AT传送门
题解
抽象题目#xff0c;抽象翻译#xff0c;可能是我太菜了#xff0c;根本没看懂题目#xff0c;后面是听大佬讲题才发现#xff0c;这不就是一题全排列暴力题吗。谔谔#xff0c;真的…【洛谷】AT_abc371_c [ABC371C] Make Isomorphic 的题解
洛谷传送门
AT传送门
题解
抽象题目抽象翻译可能是我太菜了根本没看懂题目后面是听大佬讲题才发现这不就是一题全排列暴力题吗。谔谔真的我谔谔怪不得评橙
首先先看题目意思:
给定简单无向图 G G G H H H 每个图都有 N N N 个顶点。 G G G 有 M M M 条边 H H H 有 M M M 条边。 若 H H H 中 i i i 与 j j j 间无边则添加边 若 H H H 中 i i i 与 j j j 间有边则删除边。
求使 G G G 和 H H H 同构的最小总成本。
题目非常的抽象刚开始在研究半天同构到底是什么意思qaq
题目数据范围很小只有 $ n \le 8$。所以直接暴力全排列取出最小值即可。时间复杂度 O ( n ! ) O(n!) O(n!)。脑抽想了快一个小时还是大佬教的代码
代码
#include bits/stdc.h
#define lowbit(x) x (-x)
#define endl \n
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO {inline int read() {register int x 0, f 1;register char c getchar();while (c 0 || c 9) {if(c -) f -1;c getchar();}while (c 0 c 9) x x * 10 c - 0, c getchar();return x * f;}inline void write(int x) {if(x 0) putchar(-), x -x;if(x 9) write(x / 10);putchar(x % 10 0);return;}
}
using namespace fastIO;
int n, m1, m2, G[15][15], H[15][15], edge[15][15], p[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
ll ans 0x3f3f3f3f3f3f;
int main() {//freopen(.in,r,stdin);//freopen(.out,w,stdout);n read(), m1 read();for(int i 1; i m1; i ) {int u, v;u read(), v read();G[u][v] G[v][u] 1;}m2 read();for(int i 1; i m2; i ) {int u, v;u read(), v read();H[u][v] H[v][u] 1;}for(int i 1; i n; i ) {for(int j i 1; j n; j ) {edge[i][j] read();}}do {ll temp 0;for(int i 1; i n; i ) {for(int j 1; j n; j ) {if(i ! j) {temp edge[i][j] * (G[p[i]][p[j]] ! H[i][j]);} } }ans min(ans, temp);} while(next_permutation(p 1, p n 1));cout ans endl;return 0;
}