Cod sursa(job #1571323)

Utilizator DobosDobos Paul Dobos Data 17 ianuarie 2016 20:51:33
Problema Oz Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("oz.in");
ofstream fout("oz.out");
const int NMAX = 10005;
const long long INF = 2000000000;
int V[NMAX];
int main()
{
    int n,m,x,y,d,ok = 1;
    fin >> n >> m;
    for(int i = 1; i <= n; i++)
        V[i] = 1;
    for(int i  = 1; i <= m ; i++){
        fin >> x >> y >> d;
        if(V[x] % d != 0 && (1LL*V[x]*d) <= INF )
            V[x] *= d;
        if(V[y] % d != 0 && (1LL*V[y]*d) <= INF )
            V[y] *= d;
        if((1LL*V[x]*d) > INF || (1LL*V[y]*d) > INF){
            i = m + 1;
            ok = 0;
        }
    }
    if(ok == 1)
    for(int i = 1; i <= n;i++)
        fout << V[i] << " ";
    else
        fout << -1;

    return 0;
}