#abc371c. C - Make Isomorphic
C - Make Isomorphic
Score : points
问题陈述
你得到了两个简单的无向图 和 ,每个图都有 个顶点:顶点 , , , 。图 有 条边,它的第 条边 连接顶点 和 。图 有 条边,它的第 条边 连接顶点 和 。
你可以对图 执行以下操作任意次数,可能为零次。
- 选择一对整数 满足 。支付 日元,并且如果顶点 和 在 中没有边,则添加一条;如果有,则移除它。
找出使 和 同构所需的最小总成本。
什么是简单的无向图?
简单无向图 是一个没有自环或多边的图,其中边没有方向。
图同构是什么意思?
如果存在一个排列 与 ,使得对于所有 :
- 如果图 中顶点 和 之间存在边,则图 中顶点 和 之间也存在边。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given simple undirected graphs and , each with vertices: vertices , , , . Graph has edges, and its -th edge connects vertices and . Graph has edges, and its -th edge connects vertices and .
You can perform the following operation on graph any number of times, possibly zero.
- Choose a pair of integers satisfying . Pay yen, and if there is no edge between vertices and in , add one; if there is, remove it.
Find the minimum total cost required to make and isomorphic.
What is a simple undirected graph?
A simple undirected graph is a graph without self-loops or multi-edges, where edges have no direction.
What does it mean for graphs to be isomorphic?
Two graphs and with vertices are isomorphic if and only if there exists a permutation of such that for all :
- an edge exists between vertices and in if and only if an edge exists between vertices and in .
Constraints
- $(u _ i,v _ i)\neq(u _ j,v _ j)\ (1\leq i\lt j\leq M _ G)$
- $(a _ i,b _ i)\neq(a _ j,b _ j)\ (1\leq i\lt j\leq M _ H)$
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
5
4
1 2
2 3
3 4
4 5
4
1 2
1 3
1 4
1 5
3 1 4 1
5 9 2
6 5
3
Sample Output 1
9
The given graphs are as follows:
For example, you can perform the following four operations on to make it isomorphic to at a cost of yen.
- Choose . There is an edge between vertices and in , so pay yen to remove it.
- Choose . There is no edge between vertices and in , so pay yen to add it.
- Choose . There is an edge between vertices and in , so pay yen to remove it.
- Choose . There is no edge between vertices and in , so pay yen to add it.
After these operations, becomes:
You cannot make and isomorphic at a cost less than yen, so print 9
.
Sample Input 2
5
3
1 2
2 3
3 4
4
1 2
2 3
3 4
4 5
9 1 1 1
1 1 1
1 1
9
Sample Output 2
3
For example, performing the operations on will make it isomorphic to .
Sample Input 3
5
3
1 2
2 3
3 4
4
1 2
2 3
3 4
4 5
5 4 4 4
4 4 4
4 4
5
Sample Output 3
5
For example, performing the operation once will make and isomorphic.
Sample Input 4
2
0
0
371
Sample Output 4
0
Note that and may have no edges.
Also, it is possible that no operations are needed.
Sample Input 5
8
13
1 8
5 7
4 6
1 5
7 8
1 6
1 2
5 8
2 6
5 6
6 7
3 7
4 8
15
3 5
1 7
4 6
3 8
7 8
1 2
5 6
1 6
1 5
1 4
2 8
2 6
2 4
4 7
1 3
7483 1694 5868 3296 9723 5299 4326
5195 4088 5871 1384 2491 6562
1149 6326 2996 9845 7557
4041 7720 1554 5060
8329 8541 3530
4652 3874
3748
Sample Output 5
21214