Advertisement
Guest User

ВерсутаСынСобаки

a guest
Feb 14th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  //   freopen("input.txt", "r", stdin);
  8.     int g[32];
  9.     int suf[32];
  10.     int n, m;
  11.     cin >> n >> m;
  12.    
  13.     for(int i = 1; i <= n; ++i)
  14.     {
  15.         g[i] = (1 << i);
  16.     }
  17.  
  18.     for(int i = 0; i < m; ++i)
  19.     {
  20.         int a, b;
  21.         cin >> a >> b;
  22.         g[a] |= (1 << b);
  23.         g[b] |= (1 << a);
  24.     }
  25.  
  26.     suf[n + 1] = 0;
  27.     for(int i = n; i > 0; --i)
  28.     {
  29.         suf[i] = suf[i + 1] | g[i];
  30.     }
  31.    
  32.     int nm[32];
  33.     int cur[32];
  34.    
  35.     int ptr = 1;
  36.     nm[ptr] = 1;
  37.     cur[0] = 0;
  38.     cur[ptr] = 0;
  39.    
  40.     int ans = 0;
  41.     int np1 = n + 1;
  42.     int msk = (1 << (n + 1)) - 2;
  43.  
  44.     versuta:
  45.     if(ptr == 0)
  46.     {
  47.         cout << ans << endl;
  48.         return 0;
  49.     }
  50.     if(cur[ptr] == msk)
  51.     {
  52.         ans += (1 << (n + 1 - ptr));
  53.         --ptr;
  54.         goto versuta;
  55.     }
  56.     if(ptr == np1)
  57.     {
  58.         --ptr;
  59.         goto versuta;
  60.     }
  61.     if(nm[ptr] == -1)
  62.     {
  63.         --ptr;
  64.         goto versuta;
  65.     }
  66.     if((cur[ptr] | suf[ptr]) != msk)
  67.     {
  68.         --ptr;
  69.         goto versuta;
  70.     }
  71.     if(nm[ptr] == 0)
  72.     {
  73.         cur[ptr + 1] = cur[ptr];
  74.         nm[ptr] = -1;
  75.         ++ptr;
  76.         nm[ptr] = 1;
  77.         goto versuta;
  78.     }
  79.     if(nm[ptr] == 1)
  80.     {
  81.         cur[ptr + 1] = g[ptr] | cur[ptr];
  82.         nm[ptr] = 0;
  83.         ++ptr;
  84.         nm[ptr] = 1;
  85.         goto versuta;
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement