Cod sursa(job #1232864)

Utilizator space.foldingAdrian Soucup space.folding Data 24 septembrie 2014 08:55:14
Problema Oz Scor 75
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <fstream>
#include <ctime>
#include <bitset>
#include <limits>
#include <numeric>
#include <list>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <cctype>
using namespace std;
#define x first
#define y second

long long cmmdc(long long a, long long b) {
	long long r;
	do {
		r = a % b;
		a = b;
		b = r;
	} while(r);
	return a;
}

int main () {
#ifndef ONLINE_JUDGE
	freopen("oz.in", "r", stdin);
	freopen("oz.out", "w", stdout);
#endif
	cin.sync_with_stdio(false);
	int n, m;
	cin >> n >> m;



	vector<long long> v(n, 1);

	for(int i = 0; i < m; i++) {
		int a, b;
		long long d;
		cin >> a >> b >> d;

		v[a - 1] *= (d / cmmdc(v[a - 1], d));
		v[b - 1] *= (d / cmmdc(v[b - 1], d));

		if(v[a - 1] > 2000000000LL || v[b - 1] > 2000000000LL) {
			cout << "-1";
			return 0;
		}
	}

	for(int i = 0; i < v.size(); i++)
		cout << v[i] <<  " ";

	return 0;
}