Cod sursa(job #3375959)
| Utilizator | Data | 14 noiembrie 2026 16:20:10 | |
|---|---|---|---|
| Problema | Oz | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <fstream>
using namespace std;
ifstream fin("oz.in");
ofstream fout("oz.out");
int main()
{
int n,m,v[10001];
fin>>n>>m;
int x,y,z;
for(int i=1;i<=n;i++){
v[i]=1;
}
for(int i=1;i<=m;i++){
fin>>x>>y>>z;
int cx,cy;
cx=v[x];
cy=v[y];
while(cy!=0){
int r=cx%cy;
cx=cy;
cy=r;
}
if(cx==1){
v[x]*=z;
v[y]*=z;
}else{
v[x]*=z/cx;
v[y]*=z/cx;
}
}
for(int i=1;i<=n;i++){
fout<<v[i]<<" ";
}
return 0;
}
