Cod sursa(job #1417153)

Utilizator AndreiD31Dragan Andrei AndreiD31 Data 9 aprilie 2015 18:29:44
Problema Oz Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>

using namespace std;
struct oz
{int a,b,d;

}v[100001];

int cmmmc(int a,int b)
  {int c,x,y;
  x=a;y=b;
   while(b!=0)
   {c=a%b;
    a=b;
    b=c;
   }
      return (x*y)/a;
  }
long long i,t[10001],n,m,ok;
int main()
{ifstream f("oz.in");
ofstream g("oz.out");
  f>>n>>m;
  for(i=1;i<=n;i++)t[i]=1;
  for(i=1;i<=m;i++)
    {f>>v[i].a>>v[i].b>>v[i].d;
     t[v[i].a]=cmmmc(t[v[i].a],v[i].d);
     t[v[i].b]=cmmmc(t[v[i].b],v[i].d);
    }
    ok=1;
    for(i=1;i<=n;i++)if(t[i]>2000000000)ok=0;
    if(ok==1)for(i=1;i<=n;i++)g<<t[i]<<" ";
     else g<<-1;
    return 0;
}