Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- struct Grafo
- {
- vector <vector <int> > adj;
- vector <bool> v;
- int cont = 0;
- void DFS(int n)
- {
- cont++;
- v[n] = true;
- for(int i=0; i<adj[n].size(); i++)
- if(!v[adj[n][i]])
- DFS(adj[n][i]);
- }
- int leer(int nodos, vector <pair<int, int> > lista, int k)
- {
- adj.resize(nodos+1);
- v = vector <bool> (nodos+1, false);
- for(int i=0; i<lista.size(); i++)
- {
- if(i != k)
- {
- int a = lista[i].first;
- int b = lista[i].second;
- adj[a].push_back(b);
- adj[b].push_back(a);
- }
- }
- for(int i=1; i<=nodos; i++)
- {
- if(!v[i])
- {
- cont = 0;
- DFS(i);
- if(cont%2 == 0)
- return 1;
- }
- }
- return 0;
- }
- };
- int main()
- {
- int nodos, aristas;
- cin >> nodos >> aristas;
- vector <pair<int, int> > lista(aristas);
- for(int i=0; i<aristas; i++)
- cin >> lista[i].first >> lista[i].second;
- int rta = 0;
- for(int i=0; i<aristas; i++)
- {
- Grafo g;
- rta += g.leer(nodos, lista, i);
- }
- cout << rta << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment