Cod sursa(job #3228254)

Utilizator popescu_georgePopescu George popescu_george Data 7 mai 2024 09:40:03
Problema Parcurgere DFS - componente conexe Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.4 kb
#include<bits/stdc++.h>
using namespace std;
ifstream F("dfs.in");
ofstream G("dfs.out");
int n,i,j,c;
vector<int> a[100001];
bitset<100001> b;
void A(int i)
{
    b[i]=1;
    for(int j:a[i])
        if(!b[j])
            A(j);
}
int main()
{
    for(F>>n>>i;F>>i>>j;a[i].push_back(j),a[j].push_back(i));
    for(i=1;i<=n;++i)
        if(!b[i])
            A(i),++c;
    return G<<c,0;
}