P28570 [洛谷] [SCOI2008] Balance
提高+
题目描述

Problem Description

You have $n$ weights, each of which is either 1 gram, 2 grams, or 3 grams. You do not know the exact weight of each weight, but you know the relative weights of some of them. You place two weights A and B on the left side of a balance and need to select two other weights to place on the right side. How many ways can you select these two weights such that the left side is heavier ($c_1$), the sides are equal ($c_2$), or the right side is heavier ($c_3$)? (Only selections that guarantee a unique outcome are counted.)

Input Format

The first line contains three positive integers $n$, $A$, $B$ ($1 \le A, B \le n$, $A \neq B$).

The following $n$ lines contain a weight relation matrix, where the $i$-th row and $j$-th column character is a plus sign + if weight $i$ is heavier than weight $j$, a minus sign - if weight $i$ is lighter than weight $j$, an equals sign = if weight $i$ is the same as weight $j$, and a question mark ? if the relationship between the two weights is unknown.

The data guarantees that at least one scenario matches this matrix.

Output Format

Output a single line containing three integers, $c_1$, $c_2$, and $c_3$.

Sample Input and Output

Input Sample #1

6 2 5
?+????
-?+???
?-????
????+?
???-?+
????-?

Output Sample #1

1 4 1

Input Sample #2

14 8 4
?+???++?????++
-??=?=???????=
??????????=???
?=??+?==??????
???-???-???-??
-=????????????
-??=???=?-+???
???=+?=???????
??????????????
??????+???????
??=???-????-??
????+?????+???
-?????????????
-=????????????

Output Sample #2

18 12 11

Notes

$4 \le n \le 50$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
6 2 5 ?+???? -?+??? ?-???? ????+? ???-?+ ????-?
样例输出
1 4 1