Cod sursa(job #3147050)

Utilizator sorinturdaSorin Turda sorinturda Data 23 august 2023 21:56:46
Problema Oz Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 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);
    while (m--) {
        ull i, j, d;
        in >> i >> j >> d;
        if (ans[i] == 0)
            ans[i] = d;
        else
            __gcd(ans[i], d) == 1 ? ans[i] *= d : ans[i] = ans[i] / __gcd(ans[i], d) * d;
        if (ans[j] == 0)
            ans[j] = d;
        else
            __gcd(ans[j], d) == 1 ? ans[j] *= d : ans[j] = ans[j] / __gcd(ans[j], d) * d;
    }
    for (auto it : ans)
        if (it)
            out << it << ' ';
    out << '\n';
    return 0;
}