Cod sursa(job #3138822)

Utilizator Ruxandra009Ruxandra Vasilescu Ruxandra009 Data 22 iunie 2023 16:39:55
Problema Oz Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <vector>

using namespace std;

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

int n, m, A[10005];

int cmmdc(int a, int b)
{
    while(b)
    {
        int r = a % b;
        a = b;
        b = r;
    }

    return a;
}

int main()
{
    f >> n >> m;

    for(int i = 1; i <= m; i ++)
    {
        int x, y, d;
        f >> x >> y >> d;

        if(!A[x])
            A[x] = d;
        else
        {
            int c = cmmdc(d, A[x]);
            A[x] = (A[x] * d) / c;
        }

        if(!A[y])
            A[y] = d;
        else
        {
            int c = cmmdc(d, A[y]);
            A[y] = (A[y] * d) / c;
        }
    }

    for(int i = 1; i <= n; i ++)
        g << A[i] << " ";
    return 0;
}