Cod sursa(job #812160)

Utilizator TodeaDariustodea darius TodeaDarius Data 13 noiembrie 2012 15:59:36
Problema Arbore partial de cost minim Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include<fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
#define nrmax 100005 
int n,m,t[nrmax];
int rad(int x)
{
	if(t[x]==0)
	 return x;
	else
	 return rad(t[x]);
}
void citire()
{
	f>>n>>m;int op,x,y,r1,r2;
	for(int i=1;i<=m;i++)
	{
		f>>op>>x>>y;
		r1=rad(x);
		r2=rad(y);
		if(op==1)
		{
			t[r2]=r1;
		}
		else
		{
			if(r1==r2) g<<"DA"<<'\n';
			else g<<"NU"<<'\n';
		}
	}
}
int main()
{
	citire();
	return 0;
}