Advertisement
SorahISA

2019 NHSPC north1 pF

Nov 13th, 2019
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.20 KB | None | 0 0
  1. #pragma GCC optimized("Ofast, unroll-loops")
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  7. #define X first
  8. #define Y second
  9. #define Push push_back
  10. #define ALL(x) x.begin(), x.end()
  11.  
  12. using lli = long long;
  13. using pll = pair<lli, lli>;
  14. using Double = long double;
  15. template<typename T>
  16. using Vector = vector<vector<T>>;
  17. template<typename T>
  18. using prior = priority_queue<T>;
  19.  
  20. set<pair<int,int>> beside;
  21. vector<int> vs[16];
  22. vector<bool> used(16, false);
  23. vector<int> color(16, 0);
  24. vector<lli> ans(16, 0);
  25.  
  26. int maxn;
  27.  
  28. void dfs(int now) {
  29.     if (now > maxn) {
  30.         ++ans[color[1]];
  31. //      for (int i = 1; i <= maxn; ++i) cout << color[i] << " ";
  32. //      cout << "\n";
  33.         return;
  34.     }
  35.    
  36.     for (int i = 1; i <= maxn; ++i) {
  37.         if (!used[i]) {
  38.             bool flag = true;
  39.             for (auto x : vs[now]) {
  40.                 if (beside.count({color[x], i})) {
  41.                     flag = false;
  42.                     break;
  43.                 }
  44.             }
  45.            
  46.             if (flag) {
  47.                 used[i] = true;
  48.                 color[now] = i;
  49.                 dfs(now + 1);
  50.                 used[i] = false;
  51.             }
  52.         }
  53.     }
  54. }
  55.  
  56. bool cmp(pair<int,int> a, pair<int,int> b) {
  57.     if (a.X == b.X) return a.Y < b.Y;
  58.     return a.X < b.X;
  59. }
  60.  
  61. int main() {
  62.     IOS;
  63.    
  64.     int n, m;
  65.     cin >> n >> m;
  66.    
  67.     if (n == 1) {
  68.         cout << "1\n1\n";
  69.         return 0;
  70.     }
  71.     if (n == 2) {
  72.         cout << "1\n2\n";
  73.         return 0;
  74.     }
  75.     if (m == 0) {
  76.         lli _ans = 1;
  77.         for (int i = 2; i < n*(n+1)/2; ++i) _ans *= i;
  78.         cout << 1 << "\n";
  79.         cout << _ans << "\n";
  80.         return 0;
  81.     }
  82.    
  83.     if (n >= 3) {
  84.         int tok = 1;
  85.         for (int i = 1; i <= n; ++i) {
  86.             for (int j = 1; j <= i; ++j) {
  87.                 if (j != 1) vs[tok].Push((i - 2) * (i - 1) / 2 + j - 1);
  88.                 if (j != i) vs[tok].Push((i - 2) * (i - 1) / 2 + j);
  89.                 if (j != 1) vs[tok].Push(tok - 1);
  90.                 ++tok;
  91.             }
  92.         }
  93.        
  94.         maxn = n * (n + 1) / 2;
  95.        
  96.         int a, b;
  97.         vector<pair<int,int>> Size(maxn + 1, {0, 0});
  98.         for (int i = 1; i <= maxn; ++i) Size[i].Y = i;
  99.        
  100.         for (int i = 0; i < m; ++i) {
  101.             cin >> a >> b;
  102.             beside.insert({a, b});
  103.             beside.insert({b, a});
  104.             ++Size[a].X;
  105.             ++Size[b].X;
  106.         }
  107.        
  108.         sort(ALL(Size), cmp);
  109.        
  110.         if (n == 5) {
  111.             vector<pair<int,int>> REAL;
  112.             for (int i = 1; i <= 4; ++i) {
  113.                 int j = Size[i].Y;
  114.                 used[j] = true;
  115.                 color[1] = j;
  116.                 dfs(2);
  117.                 used[j] = false;
  118.                 if (ans[j]) {
  119.                     REAL.Push({ans[j], j});
  120.                 }
  121.             }
  122.            
  123.             sort(ALL(REAL));
  124.             cout << REAL[0].Y << "\n";
  125.             cout << REAL[0].X << "\n";
  126.             return 0;
  127.         }
  128.         else {
  129.             vector<pair<int,int>> REAL;
  130.             for (int i = 1; i <= maxn; ++i) {
  131.                 int j = Size[i].Y;
  132.                 used[j] = true;
  133.                 color[1] = j;
  134.                 dfs(2);
  135.                 used[j] = false;
  136.                 if (ans[j]) {
  137.                     REAL.Push({ans[j], j});
  138.                 }
  139.             }
  140.            
  141.             sort(ALL(REAL));
  142.             cout << REAL[0].Y << "\n";
  143.             cout << REAL[0].X << "\n";
  144.             return 0;
  145. //          for (int i = 1; i <= maxn; ++i) {
  146. //              used[i] = true;
  147. //              color[1] = i;
  148. //              dfs(2);
  149. //              used[i] = false;
  150. //          }
  151.         }
  152.        
  153.         lli minAns = 1E18, minTok = -1;
  154.         for (int i = 1; i <= maxn; ++i) {
  155. //          cout << "Color " << i << ": " << ans[i] << "\n";
  156.             if (ans[i] == 0) continue;
  157.             else if (ans[i] < minAns) {
  158.                 minAns = ans[i];
  159.                 minTok = i;
  160.             }
  161.         }
  162.        
  163.         cout << minTok << "\n";
  164.         cout << minAns << "\n";
  165.     }
  166.  
  167.     return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement