Cod sursa(job #3186399)

Utilizator Vlad_NistorNIstor Vlad Vlad_Nistor Data 22 decembrie 2023 21:46:45
Problema Oz Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <bits/stdc++.h>
using namespace std;
#define MMAX 100001
#define NMAX 10001
#define int long long

pair<int,pair<int,int>> t[MMAX];
int a[NMAX];

void init(){
    for(int i = 1;i<=NMAX-1;i++){
        a[i] = 1;
    }
}

int cmmmc(int a, int b){
    return a / __gcd(a,b) * b;
}

signed main(void){
    ofstream cout("oz.out");
    ifstream cin("oz.in");
    init();

    int n,m,x;
    cin >> n >> m;
    for(int i = 1;i<=m;i++){
        cin >> t[i].first >> t[i].second.first >> x;
        a[t[i].first] = cmmmc(a[t[i].first], x);
        a[t[i].second.first] = cmmmc(a[t[i].second.first], x);
        t[i].second.second = x;
    }
    for(int i = 1;i<=m;i++){
        if(__gcd(a[t[i].first], a[t[i].second.first]) != t[i].second.second){
            cout << -1;
            return 0;
        }
    }
    for(int i= 1;i<=n;i++){
        cout << a[i] << ' ';
    }
}