A11544 | New Year and Boolean Bridges
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Your friend has a hidden directed graph with $n$ nodes.
Let $f(u,v)$ be true if there is a directed path from node $u$ to node $v$ , and false otherwise. For each pair of distinct nodes, $u,v$ , you know at least one of the three statements is true:
1. 
2. 
3. 
Here AND, OR and XOR mean AND, OR and exclusive OR operations, respectively.
You are given an $n$ by $n$ matrix saying which one of the three statements holds for each pair of vertices. The entry in the $u$ -th row and $v$ -th column has a single character.
1. If the first statement holds, this is represented by the character 'A'.
2. If the second holds, this is represented by the character 'O'.
3. If the third holds, this is represented by the character 'X'.
4. The diagonal of this matrix will only contain the character '-'.
Note that it is possible that a pair of nodes may satisfy multiple statements, in which case, the character given will represent one of the true statements for that pair. This matrix is also guaranteed to be symmetric.
You would like to know if there is a directed graph that is consistent with this matrix. If it is impossible, print the integer -1. Otherwise, print the minimum number of edges that could be consistent with this information.
Let $f(u,v)$ be true if there is a directed path from node $u$ to node $v$ , and false otherwise. For each pair of distinct nodes, $u,v$ , you know at least one of the three statements is true:
1. 
2. 
3. 
Here AND, OR and XOR mean AND, OR and exclusive OR operations, respectively.
You are given an $n$ by $n$ matrix saying which one of the three statements holds for each pair of vertices. The entry in the $u$ -th row and $v$ -th column has a single character.
1. If the first statement holds, this is represented by the character 'A'.
2. If the second holds, this is represented by the character 'O'.
3. If the third holds, this is represented by the character 'X'.
4. The diagonal of this matrix will only contain the character '-'.
Note that it is possible that a pair of nodes may satisfy multiple statements, in which case, the character given will represent one of the true statements for that pair. This matrix is also guaranteed to be symmetric.
You would like to know if there is a directed graph that is consistent with this matrix. If it is impossible, print the integer -1. Otherwise, print the minimum number of edges that could be consistent with this information.
输入格式
The first line will contain an integer $n$ ( $1<=n<=47$ ), the number of nodes.
The next $n$ lines will contain $n$ characters each: the matrix of what you know about the graph connectivity in the format described in the statement.
The next $n$ lines will contain $n$ characters each: the matrix of what you know about the graph connectivity in the format described in the statement.
输出格式
Print the minimum number of edges that is consistent with the given information, or -1 if it is impossible.
输入输出样例
输入 #1
4 -AAA A-AA AA-A AAA-
输出 #1
4
输入 #2
3 -XX X-X XX-
输出 #2
2
Sample 1: The hidden graph is a strongly connected graph. We can put all four nodes in a cycle.
Sample 2: One valid graph is $3→1→2$ . For each distinct pair, exactly one of $f(u,v),f(v,u)$ holds.
Sample 2: One valid graph is $3→1→2$ . For each distinct pair, exactly one of $f(u,v),f(v,u)$ holds.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted