Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #define _CRT_SECURE_NO_WARNINGS
  5.  
  6. #include <bits/stdc++.h>
  7.  
  8. #define TASK "kcolors"
  9.  
  10. using namespace std;
  11.  
  12. typedef int ll;
  13. typedef long double ld;
  14. #define all(x) (x).begin(),(x).end()
  15. #define sz(x) ((long long)(x).size())
  16. #define elif else if
  17. const ld eps = 1e-9;
  18. const ll inf = numeric_limits<ll>::max() / 2 - 1;
  19. const ll mod = 1000000007;
  20. const ll maxn = 14;
  21. const ll maxm = 23456;
  22. /*
  23. char mem[200000000];
  24. int mpos = 0;
  25.  
  26. void *operator new(size_t n) {
  27.     void *ans = mem + mpos;
  28.     if (mpos + n >= 200000000) mpos = 0;
  29.     mpos += n;
  30.     return ans;
  31. }
  32.  
  33. void operator delete(void *p) {}*/
  34. #define int char
  35.  
  36. vector<int> edges[maxn];
  37. vector<int> pedges[maxn];
  38. vector<int> color;
  39. int ans = 13;
  40.  
  41. inline void ae(int a, int b) {
  42.     edges[a].push_back(b);
  43.     pedges[b].push_back(a);
  44. }
  45.  
  46. inline bool dfs(int v, const int &k, bool is0) {
  47.     if (clock() * 1000 / CLOCKS_PER_SEC > 1950) {
  48.         cout << (long long) ans;
  49.         exit(0);
  50.     }
  51.     vector<bool> can(k, 1);
  52.     for (auto i : edges[v]) {
  53.         if (color[i] != -1) can[color[i]] = 0;
  54.     }
  55.     if (can.empty()) return false;
  56.     for (int c = 0; c < (is0 ? 1 : k); ++c) {
  57.         if (!can[c]) continue;
  58.         color[v] = c;
  59.         bool ans = true;
  60.         for (auto i : edges[v]) {
  61.             if (color[i] == -1) {
  62.                 ans = dfs(i, k, 0);
  63.                 if (!ans) break;
  64.             }
  65.         }
  66.         if (ans) return true;
  67.     }
  68.     color[v] = -1;
  69.     return false;
  70. }
  71.  
  72. inline int run() {
  73.     ll n, m;
  74.     cin >> n >> m;
  75.     color.assign(n, -1);
  76.     for (int i = 0; i < m; ++i) {
  77.         ll a, b;
  78.         cin >> a >> b;
  79.         a--;
  80.         b--;
  81.         ae(a, b);
  82.         ae(b, a);
  83.     }
  84.     ans = 13;
  85.     while (ans != 1) {
  86.         int k = ans - 1;
  87.         bool bans = true;
  88.         color.assign(n, -1);
  89.         for (int i = 1; i < n; ++i) {
  90.             if (color[i] == -1) {
  91.                 if (!dfs(i, k, 1)) {
  92.                     bans = false;
  93.                     break;
  94.                 }
  95.             }
  96.         }
  97.         if (!bans) {
  98.             cout << (long long) ans;
  99.             return 0;
  100.         }
  101.         ans--;
  102.     }
  103.     cout << (long long) ans;
  104.     return 0;
  105. }
  106.  
  107. signed main() {
  108.     ios_base::sync_with_stdio(false);
  109.     cin.tie(0);
  110.     cout.tie(0);
  111.  
  112. #ifdef LOCAL
  113.     freopen("input.txt", "r", stdin);
  114. #else
  115.     if (strlen(TASK) > 0) {
  116.         freopen(TASK".in", "r", stdin);
  117.         freopen(TASK".out", "w", stdout);
  118.     }
  119. #endif
  120.     run();
  121.     return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement