Cod sursa(job #448873)

Utilizator darrenRares Buhai darren Data 4 mai 2010 21:45:19
Problema Oz Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<fstream>
using namespace std;


void read();
void write();
int cmmdc( int a, int b )
{
	if ( b == 0 )
		return a;
	return cmmdc( b, a % b );
}
int cmmmc( int a, int b )
{
	return a * b / cmmdc( a, b );
}

int n, m;
int a[10001];

int main()
{
	read();
	write();
	return 0;
}

void read()
{
	ifstream fin( "oz.in" );
	fin >> n >> m;
	int i, j, d;
	for ( int x = 0; x < m; ++x )
	{
		fin >> i >> j >> d;
		if ( a[i] != 0 )
			a[i] = cmmmc( a[i], d );
		else
			a[i] = d;
		if ( a[j] != 0 )
			a[j] = cmmmc( a[j], d );
		else
			a[j] = d;
	}
}

void write()
{
	ofstream fout( "oz.out" );
	for ( int i = 1; i <= n; ++i )
		fout << a[i] << ' ';
	fout << '\n';
	fout.close();
}