Cod sursa(job #3175931)

Utilizator Mamut2Dasdasfasfas Mamut2 Data 26 noiembrie 2023 15:54:57
Problema Componente biconexe Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <fstream>
#include <vector>
#include <stack>
#define x first
#define y second

using namespace std;

ifstream fin("biconex.in");
ofstream fout("biconex.out");

vector<int> g[100001];
stack<pair<int , int>> s;
int n, m, p[100001], v[100001], low[100001], niv[100001], timp, c;

void dfs(int k, int dad){
    v[k] = 1;
    low[k] = niv[k] = ++timp;
    for(int e : g[k]){
        if(!v[e]) {
            s.push({dad, k});
            dfs(e, k);
    
            if(low[e] >= niv[k]) {
                c++;
            }

            low[k] = min(low[k], low[e]);
        }
        else if(e != dad) low[k] = min(low[k], niv[e]);
    }
}

int main(){
    fin >> n >> m;
    for(int i = 1; i <= m; i++){
        int x, y;
        fin >> x >> y;
        g[x].push_back(y), g[y].push_back(x);
    }
    dfs(1, -1);
    fout << c;
    return 0;
}