Cod sursa(job #3341890)

Utilizator RuxandraPro12_Metehau Ruxandra Maria RuxandraPro12_ Data 21 februarie 2026 14:30:47
Problema Oz Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <bits/stdc++.h>

using namespace std;

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

const int N_MAX = 10005;

int n, m, v[N_MAX], x, y, z;

int gcd (int a, int b) {
    while (b != 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

int main() {
    fin >> n >> m;
    for (int i = 1; i <= n; i++) v[i] = 1;
    for (int i = 1; i <= m; i++) {
        fin >> x >> y >> z;
        v[x] = v[x] * z / gcd(v[x], z);
        v[y] = v[y] * z / gcd(v[y], z);
    }
    for (int i = 1; i <= n; i++) fout << v[i] << "\n";
    return 0;
}