Pagini recente » Cod sursa (job #1547299) | Cod sursa (job #739002) | Cod sursa (job #1508158) | Istoria paginii runda/321/clasament | Cod sursa (job #2592847)
#include <fstream>
#include <iostream>
using namespace std;
const int MAXM = 200005;
pair<int, int> prop[MAXM];
int main()
{
ifstream fin("2sat.in");
ofstream fout("2sat.out");
int n, m;
fin >> n >> m;
for(int i = 1; i <= m; ++i){
int x, y;
fin >> x >> y;
prop[i] = {x, y};
}
for(int i = 0; i < (1 << n); ++i){
bool expr = 1;
for(int j = 1; j <= m; ++j){
bool x = ((i & (1 << (abs(prop[j].first) - 1))) > 0), y = ((i & (1 << (abs(prop[j].second) - 1))) > 0);
if(prop[j].first < 0) x = !x;
if(prop[j].second < 0) y = !y;
expr &= (x | y);
}
if(expr){
for(int j = 0; j < n; ++j) fout << ((i & (1 << j)) > 0) << " ";
return 0;
}
}
fout << -1;
return 0;
}