Pagini recente » Cod sursa (job #1572440) | Profil M@2Te4i | Cod sursa (job #2742438) | Cod sursa (job #441126) | Cod sursa (job #165775)
Cod sursa(job #165775)
//#define DODEBUG
#include <fstream>
#ifdef DODEBUG
#include <iostream>
#endif
#include <vector>
#include <exception>
using namespace std;
int main (void)
{
#ifdef DODEBUG
try{
#endif
int N,M;
ifstream f_in("oz.in");
ofstream f_out("oz.out");
f_in>>N>>M;
vector<unsigned int> num(N, 1);
for (int i=0; i<M; i++) {
int n1,n2,div;
f_in>>n1>>n2>>div;
if (div==1)div=2;
num[n1-1] *= div;
num[n2-1] *= div;
}
bool areSol=true;
for (vector<unsigned int>::const_iterator iter=num.begin();
iter != num.end() && areSol; ++iter)
if (*iter == 1) areSol=false;
if (areSol) {
for (vector<unsigned int>::const_iterator iter=num.begin();
iter != num.end(); ++iter)
f_out << *iter << ' ';
} else f_out << "-1";
f_out << '\n';
f_in.close();
f_out.close();
#ifdef DODEBUG
}catch (const exception &e) { cout<<"Caught exception: "<<e.what()<<'\n'; }
#endif
return 0;
}