Pagini recente » Cod sursa (job #305499) | Cod sursa (job #556685) | Cod sursa (job #2355012) | Cod sursa (job #1541283) | Cod sursa (job #3308904)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("oz.in");
ofstream fout ("oz.out");
void usain_bolt()
{
ios::sync_with_stdio(false);
fin.tie(0);
}
void solve()
{
int n, m;
fin >> n >> m;
vector<int> a(n, -1);
vector<tuple<int, int, int>> tuples(m);
for (auto& [x, y, z] : tuples) {
fin >> x >> y >> z;
--x, --y;
if (a[x] == -1) {
a[x] = z;
}
if (a[y] == -1) {
a[y] = z;
}
a[x] = a[x] * z / __gcd(a[x], z);
a[y] = a[y] * z / __gcd(a[y], z);
}
for (auto& [x, y, z] : tuples) {
if (__gcd(a[x], a[y]) != z) {
fout << -1 << '\n';
return;
}
}
for (auto val : a) {
if (val == -1) {
val = 1;
}
fout << val << ' ';
}
fout << '\n';
return;
}
int main()
{
usain_bolt();
int tt;
tt = 1;
while (tt--) {
solve();
}
return 0;
}