Skip to content

Commit

Permalink
129B
Browse files Browse the repository at this point in the history
  • Loading branch information
userr2232 committed Jul 27, 2021
1 parent dcc3671 commit d848049
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ lib/
pyvenv.cfg
**/*.out
Codeforces/C/225.cc
UVa/10461.cc
**/*.txt
41 changes: 41 additions & 0 deletions Codeforces/B/129.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <map>
#include <unordered_set>
#include <iostream>
#include <iterator>

using namespace std;

int main() {
int n, m, a, b;
cin >> n >> m;
map<int, unordered_set<int>> adj;
for(int i = 0; i < m; ++i) {
cin >> a >> b;
adj[a].insert(b);
adj[b].insert(a);
}
unordered_set<int> to_kick, remaining;
for(int student = 1; student <= n; ++student) {
remaining.insert(student);
}
int answer{0};
while(true) {
for(auto student : remaining) {
if(adj[student].size() == 1)
to_kick.insert(student);
}
if(!to_kick.empty()) {
++answer;
for(auto student_to_kick : to_kick) {
remaining.erase(student_to_kick);
for(auto other_student : adj[student_to_kick])
adj[other_student].erase(student_to_kick);
}
}
else{
break;
}
to_kick = {};
}
cout << answer << endl;
}

0 comments on commit d848049

Please sign in to comment.