Pagini recente » Cod sursa (job #214616) | Cod sursa (job #1876589) | Cod sursa (job #191502) | Cod sursa (job #1764557) | Cod sursa (job #166912)
Cod sursa(job #166912)
#include<fstream.h>
long x[10001],a1[100001],a2[100001],i,j,d,d2[100001],n,m,aux1,aux2;
long cmmdc(long a, long b)
{
long r;
do {
r=a%b;
a=b;
b=r;
}while (r);
return a;
}
int main()
{
ifstream f("oz.in");
f>>n>>m;
for (i=1;i<=n;i++)x[i]=1;
for (i=1;i<=m;i++)
{
f>>a1[i]>>a2[i]>>d2[i];
aux1=x[a1[i]];
aux2=x[a2[i]];
x[a1[i]]*=d2[i]/cmmdc(x[a1[i]],d2[i]);
x[a2[i]]*=d2[i]/cmmdc(x[a2[i]],d2[i]);
}
int ind=1;
for (i=1;i<=m;i++)
if (cmmdc(x[a1[i]],x[a2[i]])!=d2[i])
{
ind=0;
break;
}
f.close();
ofstream g("oz.out");
if (ind) for (i=1;i<=n;i++)g<<x[i]<<" ";
else g<<"-1";
g<<'\n';
g.close();
return 0;
}