Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <ctime>
  7. #include <string>
  8.  
  9.  
  10. #define y1 y11
  11. #define pi acos(-a)
  12. #define eps (double)(1e-9)
  13. #define pb push_back
  14.  
  15. using namespace std;
  16.  
  17.  
  18. int col = 0;
  19. vector<int> g[250];
  20. bool used[250];
  21. int d[250][250];
  22. int color[250];
  23. int deg[250];
  24. int c[250];
  25.  
  26. void dfs(int u, int col)
  27. {
  28.     used[u] = true;
  29.     color[u] = col;
  30.     for (int i = 0; i < g[u].size(); i++)
  31.     {
  32.         int v = g[u][i];
  33.         if (!used[v])
  34.             dfs(v, col);
  35.     }
  36. }
  37.  
  38. int main()
  39. {
  40.     //freopen("domino.in", "r", stdin);
  41.     //freopen("domino.out", "w", stdout);
  42.     int n, m;
  43.     cin >> m >> n;
  44.     for(int i = 0; i < m + 1; i++)
  45.     {
  46.         for (int j = 0; j < m + 1; j++)
  47.             if (i != j)
  48.                 d[i][j] = 1;
  49.         deg[i] = m + 1;
  50.     }
  51.     for(int i = 0; i < n; i++)
  52.     {
  53.         int a, b;
  54.         cin >> a >> b;
  55.         if (a != b){
  56.             d[a][b] = 0;
  57.             d[b][a] = 0;
  58.             deg[a]--;
  59.             deg[b]--;
  60.         }
  61.         if (a == b){
  62.             d[a][a] = 0;
  63.             deg[a]--;
  64.         }
  65.     }
  66.     for(int i = 0; i < m + 1; i++)
  67.         for (int j = 0; j < m + 1; j++)
  68.             if(d[i][j] == 1)
  69.                 g[i].pb(j);
  70.     for (int i = 0; i < (m+1); i++){
  71.         if (!used[i])
  72.         {
  73.             dfs(i, col);
  74.             col++;
  75.         }
  76.     }
  77.     for (int i = 0; i < m + 1; i++){
  78.         c[color[i]] += deg[i] % 2;
  79.     }
  80.     int ans = 0;
  81.     for (int i = 0; i < col; i++){
  82.         if (c[i] > 0)
  83.             ans += c[i] / 2;
  84.         else
  85.             ans++;
  86.     }
  87.     cout << ans;
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement