Advertisement
Georgiy1108

Untitled

Sep 23rd, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5.     int n, m, mx = 0;
  6. vector<int> color, used;
  7. vector<pair<int, int>> r;
  8.  
  9. int check(vector<int> color)
  10. {
  11.     int cnt = 0;
  12.     map<pair<int, int>, int> mp;
  13.     for(auto i : r)
  14.     {
  15.         if(mp.count({min(color[i.first], color[i.second]), max(color[i.first], color[i.second])}) == 0)
  16.         {
  17.             cnt++;
  18.             mp[{min(color[i.first], color[i.second]), max(color[i.first], color[i.second])}] = 1;
  19.         }
  20.     }
  21.     return cnt;
  22. }
  23.  
  24. void f(int i, vector<int> color, vector<int> used)
  25. {
  26.     if(i == n + 1)
  27.     {
  28.         mx = max(check(color), mx);
  29.         return;
  30.     }
  31.     for(int j = 1; j <= 6; j++)
  32.     {
  33.         if(used[j] == 1)
  34.         {
  35.             color[i] = j, used[j]++;
  36.             f(i + 1, color, used);
  37.         }
  38.         else if(used[j] == 0)
  39.         {
  40.             color[i] = j, used[j]++;
  41.             f(i + 1, color, used);
  42.         }
  43.         else if(used[j] > 1)
  44.             continue;
  45.     }
  46. }
  47.  
  48. main()
  49. {
  50.    
  51.     cin >> n >> m;
  52.     for(int i = 0; i < m; i++)
  53.     {
  54.         int f, t;
  55.         cin >> f >> t;
  56.         r.push_back({f, t});
  57.     }
  58.     color.resize(n + 1, 0);
  59.     used.resize(7, 0);
  60.     set<int> s{1, 2, 3, 4, 5, 6, 7};
  61.     f(1, color, used);
  62.     cout << mx;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement