Cod sursa(job #3232938)
Utilizator | Data | 2 iunie 2024 07:04:57 | |
---|---|---|---|
Problema | Parcurgere DFS - componente conexe | Scor | 90 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.28 kb |
#include<fstream>
using namespace std;
ifstream F("dfs.in");
ofstream G("dfs.out");
int i,n,a[100001],j,k,l;
int main()
{
for(F>>n>>j;F>>i>>j;) {
for(;a[i];i=a[i]);
for(;a[j];j=a[j]);
if(i!=j)
++l,a[i]=j;
}
return G<<n-l,0;
}