Cod sursa(job #3232931)

Utilizator popescu_georgePopescu George popescu_george Data 2 iunie 2024 06:40:13
Problema Parcurgere DFS - componente conexe Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include<bits/stdc++.h>
using namespace std;
ifstream F("dfs.in");
ofstream G("dfs.out");
#define Z 2048
int n,m,i,j,k,p=Z;
vector<int> a[100001];
bitset<100001> b;
char s[Z];
inline char A()
{
    if(p==Z)
        F.read(s,Z),p=0;
    return s[p++];
}
int B()
{
    char c;
    int n=0;
    for(c=A();isdigit(c);n=n*10+c-48,c=A());
    return n;
}
void C(int i)
{
    b[i]=1;
    for(int j:a[i])
        if(!b[j])
            C(j);
}
int main()
{
    for(n=B(),m=B();m--;i=B(),j=B(),a[i].push_back(j),a[j].push_back(i));
    for(i=1;i<=n;++i)
        if(!b[i])
            C(i),++k;
    return G<<k,0;
}