Advertisement
tsypko

Untitled

Jan 31st, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/rope>
  3. using namespace std;
  4. using namespace __gnu_cxx;
  5. typedef long long ll;
  6. typedef unsigned long long ull;
  7. typedef unsigned int ui;
  8. typedef long double ld;
  9. typedef pair<ll, ll> ii;
  10. typedef pair<ii, ii> iii;
  11. ll MOD = 1e9 + 7;
  12. const ld E = 1e-7;
  13. #define null NULL
  14. #define ms(x) memset(x, 0, sizeof(x))
  15. #ifndef LOCAL
  16. #define endl "\n"
  17. #endif
  18. #ifndef LONG_LONG_MAX
  19. #define LONG_LONG_MAX LLONG_MAX
  20. #endif
  21. #define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  22. #define _read(x) freopen(x, "r", stdin)
  23. #define _write(x) freopen(x, "w", stdout)
  24. #define files(x) _read(x ".in"); _write(x ".out")
  25. #define filesdatsol(x) _read(x ".DAT"); _write(x ".SOL")
  26. #define output _write("output.txt")
  27. #define input _read("input.txt")
  28. #define prev time_prev
  29. #define M_PI acos(-1)
  30. #define remove tipa_remove
  31. #define left tipa_left
  32. #define right tipa_right
  33. #define next tipa_next
  34. #define mod % MOD
  35. #define y1 hello_world
  36. unsigned char ccc;
  37. bool _minus = false;
  38. template<typename T>
  39. inline T sqr(T t) {
  40. return (t * t);
  41. }
  42. inline void read(ll &n) {
  43. n = 0;
  44. _minus = false;
  45. while (true) {
  46. ccc = getchar();
  47. if (ccc == ' ' || ccc == '\n')
  48. break;
  49. if (ccc == '-') {
  50. _minus = true;
  51. continue;
  52. }
  53. n = n * 10 + ccc - '0';
  54. }
  55. if (_minus)
  56. n *= -1;
  57. }
  58. inline void read(int &n) {
  59. n = 0;
  60. _minus = false;
  61. while (true) {
  62. ccc = getchar();
  63. if (ccc == ' ' || ccc == '\n')
  64. break;
  65. if (ccc == '-') {
  66. _minus = true;
  67. continue;
  68. }
  69. n = n * 10 + ccc - '0';
  70. }
  71. if (_minus)
  72. n *= -1;
  73. }
  74. char wwww[19];
  75. int kkkk;
  76. inline void write(ll y) {
  77. long long x = y;
  78. kkkk = 0;
  79. if (x < 0) {
  80. putchar('-');
  81. x *= -1;
  82. }
  83. if (!x)
  84. ++kkkk, wwww[kkkk] = '0';
  85. else
  86. while (x) {
  87. ++kkkk;
  88. wwww[kkkk] = char(x % 10 + '0');
  89. x /= 10;
  90. }
  91. for (int i = kkkk; i >= 1; --i)
  92. putchar(wwww[i]);
  93. }
  94.  
  95. #ifdef LOCAL
  96. //#define DEBUG
  97. #endif
  98.  
  99. #ifdef DEBUG
  100. #define dbg if(1)
  101. #else
  102. #define dbg if(0)
  103. #endif
  104.  
  105. const int MAX = 19;
  106. ll dp[1 << MAX][MAX];
  107.  
  108. int ar[MAX][MAX];
  109.  
  110. int bits_in(int n) {
  111. int ans = 0;
  112. while (n) {
  113. ans += n & 1;
  114. n >>= 1;
  115. }
  116. return ans;
  117. }
  118.  
  119. bool in(int mask, int i){
  120. return ((mask & (1 << i)) != 0);
  121. }
  122.  
  123. ll solve(int pos) {
  124. ms(dp);
  125. dp[1 << pos][pos] = 1;
  126. ll ans = 0;
  127. for (int i = 1; i < (1 << MAX); i++) {
  128. for (int j = 0; j < MAX; j++) {
  129. if (dp[i][j]) {
  130. if (bits_in(i) > 2 && ar[j][pos]) {
  131. ans += dp[i][j];
  132. }
  133. for (int z = pos + 1; z < MAX; z++) {
  134. if(ar[j][z] && !in(i, z)){
  135. dp[i ^ (1 << z)][z] += dp[i][j];
  136. }
  137. }
  138. }
  139. }
  140. }
  141. return ans;
  142. }
  143.  
  144. int main() {
  145. sync;
  146. srand(time(NULL));
  147. cout.precision(3);
  148. cout << fixed;
  149. #ifdef LOCAL
  150. input;
  151. #else
  152.  
  153. #endif
  154.  
  155. int n, m;
  156. cin >> n >> m;
  157.  
  158. while(m--){
  159. int a, b;
  160. cin >> a >> b;
  161. a--, b--;
  162. ar[a][b] = ar[b][a] = true;
  163. }
  164.  
  165. ll ans = 0;
  166. for(int i = 0; i < n; i++){
  167. ans += solve(i);
  168. }
  169. cout << ans / 2 << endl;
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement