A10328 | Little Artem and 2-SAT
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Little Artem is a very smart programmer. He knows many different difficult algorithms. Recently he has mastered in 2-SAT one.
In computer science, 2-satisfiability (abbreviated as 2-SAT) is the special case of the problem of determining whether a conjunction (logical AND) of disjunctions (logical OR) have a solution, in which all disjunctions consist of no more than two arguments (variables). For the purpose of this problem we consider only 2-SAT formulas where each disjunction consists of exactly two arguments.
Consider the following 2-SAT problem as an example: . Note that there might be negations in 2-SAT formula (like for $x_{1}$ and for $x_{4}$ ).
Artem now tries to solve as many problems with 2-SAT as possible. He found a very interesting one, which he can not solve yet. Of course, he asks you to help him.
The problem is: given two 2-SAT formulas $f$ and $g$ , determine whether their sets of possible solutions are the same. Otherwise, find any variables assignment $x$ such that $f(x)≠g(x)$ .
In computer science, 2-satisfiability (abbreviated as 2-SAT) is the special case of the problem of determining whether a conjunction (logical AND) of disjunctions (logical OR) have a solution, in which all disjunctions consist of no more than two arguments (variables). For the purpose of this problem we consider only 2-SAT formulas where each disjunction consists of exactly two arguments.
Consider the following 2-SAT problem as an example: . Note that there might be negations in 2-SAT formula (like for $x_{1}$ and for $x_{4}$ ).
Artem now tries to solve as many problems with 2-SAT as possible. He found a very interesting one, which he can not solve yet. Of course, he asks you to help him.
The problem is: given two 2-SAT formulas $f$ and $g$ , determine whether their sets of possible solutions are the same. Otherwise, find any variables assignment $x$ such that $f(x)≠g(x)$ .
输入格式
The first line of the input contains three integers $n$ , $m_{1}$ and $m_{2}$ ( $1<=n<=1000$ , $1<=m_{1},m_{2}<=n^{2}$ ) — the number of variables, the number of disjunctions in the first formula and the number of disjunctions in the second formula, respectively.
Next $m_{1}$ lines contains the description of 2-SAT formula $f$ . The description consists of exactly $m_{1}$ pairs of integers $x_{i}$ ( $-n<=x_{i}<=n,x_{i}≠0$ ) each on separate line, where $x_{i}>0$ corresponds to the variable without negation, while $x_{i}<0$ corresponds to the variable with negation. Each pair gives a single disjunction. Next $m_{2}$ lines contains formula $g$ in the similar format.
Next $m_{1}$ lines contains the description of 2-SAT formula $f$ . The description consists of exactly $m_{1}$ pairs of integers $x_{i}$ ( $-n<=x_{i}<=n,x_{i}≠0$ ) each on separate line, where $x_{i}>0$ corresponds to the variable without negation, while $x_{i}<0$ corresponds to the variable with negation. Each pair gives a single disjunction. Next $m_{2}$ lines contains formula $g$ in the similar format.
输出格式
If both formulas share the same set of solutions, output a single word "SIMILAR" (without quotes). Otherwise output exactly $n$ integers $x_{i}$ () — any set of values $x$ such that $f(x)≠g(x)$ .
输入输出样例
输入 #1
2 1 1 1 2 1 2
输出 #1
SIMILAR
输入 #2
2 1 1 1 2 1 -2
输出 #2
0 0
First sample has two equal formulas, so they are similar by definition.
In second sample if we compute first function with $x_{1}=0$ and $x_{2}=0$ we get the result $0$ , because . But the second formula is $1$ , because .
In second sample if we compute first function with $x_{1}=0$ and $x_{2}=0$ we get the result $0$ , because . But the second formula is $1$ , because .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted