Cod sursa(job #2485901)
| Utilizator | Data | 2 noiembrie 2019 10:34:51 | |
|---|---|---|---|
| Problema | Oz | Scor | 75 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.7 kb |
#include <fstream>
using namespace std;
ifstream in ("oz.in");
ofstream out ("oz.out");
long long cmmmc(int a,int b)
{
int r=0,ca=a,cb=b;
while(b)
{
r=a%b;
a=b;
b=r;
}
return 1LL*ca*cb/a;
}
long long v[10007];
int main()
{
int n,m,i,j,d;
in>>n>>m;
for(int a=1;a<=n;a++)
v[a]=1;
for(int cazan=1;cazan<=m;cazan++)
{
in>>i>>j>>d;
v[i]=cmmmc(v[i],d);
v[j]=cmmmc(v[j],d);
}
for(int a=1;a<=n;a++)
{
if(v[a]>2e9||v[a]<0)
{
out<<-1;
return 0;
}
}
for(int a=1;a<=n;a++)
{
out<<v[a]<<' ';
}
return 0;
}
