Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <stack>
- using namespace std;
- const int maxk=1e5+10;
- int n, m;
- vector<int>graph[maxk];
- vector<int>art;
- int low_link[maxk];
- int dist[maxk];
- bool visited[maxk];
- int current_time=0;
- void dfs(int node, int parent=-1){
- visited[node]=true;
- low_link[node]=current_time;
- dist[node]=current_time;
- current_time++;
- int children = 0;
- for(int i=0; i<(int)graph[node].size(); i++){
- int sosed=graph[node][i];
- if(sosed!=parent){
- if(visited[sosed]==true){
- low_link[node]=min(low_link[node], dist[sosed]);
- }
- else{
- dfs(sosed, node);
- low_link[node]=min(low_link[node], low_link[sosed]);
- if(parent!=-1 and low_link[sosed]>=dist[node]){
- art.push_back(node);
- }
- children++;
- }
- }
- }
- if(parent == -1 and children > 1) {
- art.push_back(node);
- }
- }
- void articulation_points(){
- for(int i=0; i<maxk; i++){
- visited[i]=false;
- dist[i]=-1;
- low_link[i]=-1;
- }
- for(int i=0; i<n; i++){
- if(visited[i]==false){
- dfs(i);
- }
- }
- }
- int main()
- {
- while(true) {
- cin>>n>>m;
- if(n == 0 and m == 0) {
- break;
- }
- for(int i=0; i<m; i++){
- int a, b;
- cin>>a>>b;
- a--;
- b--;
- graph[a].push_back(b);
- graph[b].push_back(a);
- }
- current_time=0;
- articulation_points();
- cout<<art.size() << endl;
- for(int i = 0; i < maxk; i ++) {
- graph[i].clear();
- }
- art.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement