Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <ctime>
- #include <string>
- #define y1 y11
- #define pi acos(-a)
- #define eps (double)(1e-9)
- #define pb push_back
- using namespace std;
- int col = 0;
- vector<int> g[250];
- bool used[250];
- int d[250][250];
- int color[250];
- int deg[250];
- int c[250];
- void dfs(int u, int col)
- {
- used[u] = true;
- color[u] = col;
- for (int i = 0; i < g[u].size(); i++)
- {
- int v = g[u][i];
- if (!used[v])
- dfs(v, col);
- }
- }
- int main()
- {
- //freopen("domino.in", "r", stdin);
- //freopen("domino.out", "w", stdout);
- int n, m;
- cin >> m >> n;
- for(int i = 0; i < m + 1; i++)
- {
- for (int j = 0; j < m + 1; j++)
- if (i != j)
- d[i][j] = 1;
- deg[i] = m + 1;
- }
- for(int i = 0; i < n; i++)
- {
- int a, b;
- cin >> a >> b;
- if (a != b){
- d[a][b] = 0;
- d[b][a] = 0;
- deg[a]--;
- deg[b]--;
- }
- if (a == b){
- d[a][a] = 0;
- deg[a]--;
- }
- }
- for(int i = 0; i < m + 1; i++)
- for (int j = 0; j < m + 1; j++)
- if(d[i][j] == 1)
- g[i].pb(j);
- for (int i = 0; i < (m+1); i++){
- if (!used[i])
- {
- dfs(i, col);
- col++;
- }
- }
- for (int i = 0; i < m + 1; i++){
- c[color[i]] += deg[i] % 2;
- }
- int ans = 0;
- for (int i = 0; i < col; i++){
- if (c[i] > 0)
- ans += c[i] / 2;
- else
- ans++;
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement