fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define F(i, l, r) for(auto i = l; i != r; i++)
  4. #define ret return
  5. #define pb push_back
  6. #define cont continue
  7. #define fi0(x) memset((x), 0, sizeof(x))
  8.  
  9. typedef long long int lint;
  10. const lint mod = 1000000007;
  11.  
  12. int add(int v, int u){
  13. v += u;
  14. if(v >= mod)v -= mod;
  15. ret v;
  16. }
  17.  
  18. int mul(lint v, lint u){
  19. ret (v*u)%mod;
  20. }
  21.  
  22. class RainbowGraph{
  23. public:
  24. vector<int> col;
  25. bool gr[111][111];
  26. int n, m;
  27. int dp[10][1<<11][11][11];
  28. int ptr;
  29. int revid[111];
  30. int id[11][11];
  31. int all_da_ptrs[11];
  32. int ans[1<<11][101];
  33. int countWays(vector<int> c, vector<int> a, vector<int> b){
  34. n = (int)c.size();
  35. m = (int)a.size();
  36. col = c;
  37. fi0(dp);
  38. memset(gr, 0, sizeof(gr));
  39. fi0(ans);
  40. F(i, 0, m){gr[a[i]][b[i]] = true; gr[b[i]][a[i]] = true;}
  41. F(cc, 0, 10){
  42. ptr = 0;
  43. F(i, 0, n)if(col[i] == cc){revid[i] = ptr; id[cc][ptr++] = i;}
  44. all_da_ptrs[cc] = ptr;
  45. if(ptr == 0)cont;
  46. F(mask, 1, 1<<ptr){
  47. F(v, 0, ptr){
  48. F(u, 0, ptr){
  49. if(!(mask&(1<<v)))cont;
  50. if(!(mask&(1<<u)))cont;
  51. if(__builtin_popcount(mask) != 1 && v == u)cont;
  52. if(__builtin_popcount(mask)==1){dp[cc][mask][v][u] = 1; cont;}
  53. int pmask = mask^(1<<u);
  54. F(last, 0, ptr){
  55. if(!(pmask&(1<<last)))cont;
  56. if(!gr[id[cc][last]][id[cc][u]])cont;
  57. dp[cc][mask][v][u] = add(dp[cc][mask][v][u], dp[cc][pmask][v][last]);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. F(mask, 1, 1<<10){
  64. F(cc, 0, 10)if(all_da_ptrs[cc] == 0 && mask&(1<<cc))cont;
  65. F(last, 0, n){
  66. if(!(mask&(1<<col[last])))cont;
  67. F(fst, 0, n){
  68. if(col[fst] != col[last])cont;
  69. if(dp[col[last]][(1<<all_da_ptrs[col[last]])-1][revid[fst]][revid[last]] == 0)cont;
  70. if(__builtin_popcount(mask)==1){ans[mask][last] = add(ans[mask][last], dp[col[last]][(1<<all_da_ptrs[col[last]])-1][revid[fst]][revid[last]]); cont;}
  71. int pmask = mask^(1<<col[last]);
  72. F(kek, 0, n){
  73. if(!(pmask&(1<<col[kek])) || !gr[kek][fst])cont;
  74. ans[mask][last] = add(ans[mask][last], mul(ans[pmask][kek], dp[col[last]][(1<<all_da_ptrs[col[last]])-1][revid[fst]][revid[last]]));
  75. }
  76. }
  77. }
  78. }
  79. int ama = (1<<10)-1;
  80. F(cc, 0, 10)if(all_da_ptrs[cc] == 0)ama ^= (1<<cc);
  81. int tot = 0;
  82. F(last, 0, n)tot = add(tot, ans[ama][last]);
  83. ret tot;
  84. }
  85. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty