Cod sursa(job #3232937)

Utilizator popescu_georgePopescu George popescu_george Data 2 iunie 2024 07:01:31
Problema Parcurgere DFS - componente conexe Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.35 kb
#include<fstream>
using namespace std;
ifstream F("dfs.in");
ofstream G("dfs.out");
int i,n,v[100001],j,k,l;
int main()
{
    for(F>>n>>j,i=1;i<=n;v[i]=i,++i);
    for(;F>>i>>j;) {
        for(;i!=v[i];k=v[v[i]],v[i]=k,i=k);
        for(;j!=v[j];k=v[v[j]],v[j]=k,j=k);
        if(i!=j)
            ++l,v[i]=j;
    }
    return G<<n-l,0;
}