Cod sursa(job #165775)

Utilizator stefysStefan stefys Data 26 martie 2008 20:02:27
Problema Oz Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
//#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;
}