GastonFontenla

Untitled

Jul 14th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4.  
  5. using namespace std;
  6.  
  7. struct Grafo
  8. {
  9.     vector <vector <int> > adj;
  10.     vector <bool> v;
  11.  
  12.     int cont = 0;
  13.  
  14.     void DFS(int n)
  15.     {
  16.         cont++;
  17.         v[n] = true;
  18.  
  19.         for(int i=0; i<adj[n].size(); i++)
  20.             if(!v[adj[n][i]])
  21.                 DFS(adj[n][i]);
  22.     }
  23.  
  24.     int leer(int nodos, vector <pair<int, int> > lista, int k)
  25.     {
  26.         adj.resize(nodos+1);
  27.         v = vector <bool> (nodos+1, false);
  28.  
  29.         for(int i=0; i<lista.size(); i++)
  30.         {
  31.             if(i != k)
  32.             {
  33.                 int a = lista[i].first;
  34.                 int b = lista[i].second;
  35.                 adj[a].push_back(b);
  36.                 adj[b].push_back(a);
  37.             }
  38.         }
  39.  
  40.         for(int i=1; i<=nodos; i++)
  41.         {
  42.             if(!v[i])
  43.             {
  44.                 cont = 0;
  45.                 DFS(i);
  46.                 if(cont%2 == 0)
  47.                     return 1;
  48.             }
  49.         }
  50.  
  51.         return 0;
  52.     }
  53. };
  54.  
  55. int main()
  56. {
  57.     int nodos, aristas;
  58.     cin >> nodos >> aristas;
  59.     vector <pair<int, int> > lista(aristas);
  60.  
  61.     for(int i=0; i<aristas; i++)
  62.         cin >> lista[i].first >> lista[i].second;
  63.  
  64.     int rta = 0;
  65.     for(int i=0; i<aristas; i++)
  66.     {
  67.         Grafo g;
  68.         rta += g.leer(nodos, lista, i);
  69.     }
  70.  
  71.     cout << rta << endl;
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment