-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path687_24en23C.cpp
65 lines (55 loc) · 1.16 KB
/
687_24en23C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Usuario de Acepta el reto: jjjjjjjp022
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>
using namespace std;
using lli = long long int;
int main() {
int n;
cin >> n;
while(n != 0) {
lli cont = 0;
vector<vector<int>>v(n+1);
int a, b;
cin >> a >> b;
while(a!= 0) {
if(a != b) {
v[a].push_back(b);
v[b].push_back(a);
}
else {
cont++;
}
cin >> a >> b;
}
unordered_set<int> pasados;
vector<int>frontera(1, 1);
while(frontera.size() > 0) {
int act = frontera[frontera.size()-1];
frontera.pop_back();
//cout << "act: " << act << endl;
for(int i = 0; i < v[act].size(); i++) {
//cout << "mirando " << v[act][i] << endl;
if(pasados.count(v[act][i]) == 0) {
frontera.push_back(v[act][i]);
pasados.insert(v[act][i]);
}
else {
cont++;
}
//Borrar enlace usado en destino
int j = 0;
while(j < v[v[act][i]].size() && v[v[act][i]][j] != act) {
j++;
}
if(j < v[v[act][i]].size())
v[v[act][i]].erase(v[v[act][i]].begin() + j);
/*else
cout << "ERROR";*/
}
}
cout << cont << '\n';
cin >> n;
}
}