当前位置:   article > 正文

牛客多校一 D_闵可夫斯基和 多校

闵可夫斯基和 多校

链接:https://www.nowcoder.com/acm/contest/139/D
来源:牛客网
 

题目描述

Two undirected simple graphs and where are isomorphic when there exists a bijection on V satisfying  if and only if {x, y} ∈ E2.
Given two graphs and , count the number of graphs satisfying the following condition:
* .
* G1 and G are isomorphic.

输入描述:

The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains three integers n, m1 and m2 where |E1| = m1 and |E2| = m2.
The i-th of the following m1 lines contains 2 integers ai and bi which denote {ai, bi} ∈ E1.
The i-th of the last m2 lines contains 2 integers ai and bi which denote {ai, bi} ∈ E2.

输出描述:

For each test case, print an integer which denotes the result.

示例1

输入

复制

3 1 2
1 3
1 2
2 3
4 2 3
1 2
1 3
4 1
4 2
4 3

输出

复制

2
3

备注:

* 1 ≤ n ≤ 8
* 
* 1 ≤ ai, bi ≤ n
* The number of test cases does not exceed 50.

题意:问一个图在另一个图有多少个同构。

题解:

因为每一种排列代表不同的标号。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll MOD = 1E9 + 7;
  5. int main()
  6. {
  7. ios::sync_with_stdio(false), cin.tie(0);
  8. int n, m1, m2;
  9. while(cin >> n >> m1 >> m2) {
  10. vector<int> a(n);
  11. for(int i = 0; i < n; ++i) a[i] = i;
  12. vector< pair<int, int> > edge1(m1), edge2(m2);
  13. vector<vector<int> > vis(n, vector<int>(n) );
  14. for(int i = 0; i < m1; ++i) {
  15. int u, v;
  16. cin >> u >> v;
  17. edge1[i] = {--u, --v};
  18. vis[u][v] = vis[v][u] = 1;
  19. }
  20. for(int i = 0; i < m2; ++i) {
  21. int u, v;
  22. cin >> u >> v;
  23. edge2[i] = {u - 1, v - 1};
  24. }
  25. set<ll> s;
  26. do {
  27. int cnt = 0;
  28. ll cur = 0;
  29. for(int i = 0; i < m2; i ++) {
  30. if(vis[a[edge2[i].first]][a[edge2[i].second]]) {
  31. cnt ++;
  32. cur = cur * 133 + (i + 53);
  33. cur %= MOD;
  34. }
  35. }
  36. if(cnt == m1) s.insert(cur);
  37. }while(next_permutation(a.begin(), a.end()));
  38. cout << (int)s.size() << '\n';
  39. }
  40. return 0;
  41. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/986494
推荐阅读
相关标签
  

闽ICP备14008679号