Cod sursa(job #720402)

Utilizator 5t3fristea stefan 5t3f Data 22 martie 2012 17:15:42
Problema Oz Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
// oz.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include "fstream"
using namespace std;
int main()
{
	ifstream f("oz.in");
	ofstream g("oz.out");
	int n,m;
	f>>n>>m;
	int a[10000];
	int i;
	for(i=0;i<n;i++)
		a[i]=1;
	for(i=0;i<m;i++)
	{
		int p1,p2,d;
		f>>p1>>p2>>d;
		p1--;
		p2--;
		int tmp=d,tmp1=a[p1];
		while(tmp1!=tmp)
		{
			if(tmp1>tmp)
				tmp1-=tmp;
			if(tmp>tmp1)
				tmp-=tmp1;
		}
		a[p1]=(a[p1]*d)/tmp1;
		tmp=d,tmp1=a[p2];
		while(tmp1!=tmp)
		{
			if(tmp1>tmp)
				tmp1-=tmp;
			if(tmp>tmp1)
				tmp-=tmp1;
		}
		a[p2]=(a[p2]*d)/tmp;
	}
	for(i=0;i<n;i++)
		g<<a[i]<<" ";
	return 0;
}