Nu aveti permisiuni pentru a descarca fisierul grader_test2.ok
Cod sursa(job #473670)
Utilizator | Data | 31 iulie 2010 00:06:51 | |
---|---|---|---|
Problema | Oz | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.99 kb |
#include <fstream>
using namespace std;
long long a[10100];
int n,m;
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int main() {
ifstream fin("oz.in");
ofstream fout("oz.out");
fin >> n >> m;
for (int i = 1; i <= n; ++i)
a[i] = 1;
while (m--) {
int i,j,k;
fin >> i >> j >> k;
a[i] = a[i]*k / gcd(a[i], k);
a[j] = a[j]*k / gcd(a[j], k);
if (gcd(a[i], a[j]) != k) {
fout << "-1\n";
fout.close();
return 0;
}
if (a[i] > 2000000000) {
fout << "-1\n";
fout.close();
return 0;
}
if (a[j] > 2000000000) {
fout << "-1\n";
fout.close();
return 0;
}
}
for (int i = 1; i <= n; ++i) {
if (a[i] > 2000000000) {
fout << "-1\n";
fout.close();
return 0;
}
}
for (int i = 1; i < n; ++i)
fout << a[i] << " ";
fout << a[n] << "\n";
fout.close();
return 0;
}