Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e4 + 10;
- const int M = 1e5 + 10;
- vector <int> g[N];
- unordered_set <int> ap;
- bool vs[N];
- int disc[N], low[N];
- void Setting();
- int cnt = 0;
- void tarjan(int u, int pre){
- vs[u] = true;
- cnt ++;
- disc[u] = cnt;
- low[u] = cnt;
- int child = 0;
- for(auto v: g[u]){
- if(!vs[v]){
- child ++;
- tarjan(v, u);
- low[u] = min(low[u], low[v]);
- if((pre != 0 and low[v] >= disc[u]) or (pre == 0 and child > 1))
- ap.insert(u);
- }
- else if(v != pre){
- low[u] = min(low[u], disc[v]);
- }
- }
- }
- void Solve(int n, int m){
- for(int i=1;i<=m;i++){
- int u, v;
- scanf("%d %d", &u, &v);
- g[u].push_back(v);
- g[v].push_back(u);
- }
- tarjan(1, 0);
- printf("%d", ap.size());
- Setting();
- }
- int main(){
- while(true){
- int n, m;
- scanf("%d %d", &n, &m);
- if(n == 0 and m == 0) return 0;
- Solve(n, m);
- printf("\n");
- }
- return 0;
- }
- void Setting(){
- for(int i=1;i<=N-10;i++){
- if(!g[i].empty()) g[i].clear();
- }
- if(!ap.empty()) ap.clear();
- for(int i=1;i<=N-10;i++){
- vs[i] = false;
- disc[i] = 0;
- low[i] = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement