Cod sursa(job #3147054)

Utilizator sorinturdaSorin Turda sorinturda Data 23 august 2023 22:12:55
Problema Oz Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
//https://www.infoarena.ro/problema/oz
#include <bits/stdc++.h>

using namespace std;

ifstream in("oz.in");
ofstream out("oz.out");

using ull = unsigned long long;

int main() {
    ios_base::sync_with_stdio(false);
    in.tie(NULL);
    out.tie(NULL);

    ull n, m;
    in >> n >> m;
    vector<ull>ans(n + 1, 1);
    while (m--) {
        ull i, j, d;
        in >> i >> j >> d;
        ans[i] = d * __gcd(d, ans[i]) * ans[i];
        ans[j] = d * __gcd(d, ans[j]) * ans[j];
        if (__gcd(ans[i], ans[j]) != d) {
            out << -1 << '\n';
            return 0;
        }
    }
    for (auto it : ans)
        if (it != 1)
            out << it << ' ';
    out << '\n';
    return 0;
}