CF40E.Number Table

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

As it has been found out recently, all the Berland's current economical state can be described using a simple table n×mn×m in size. nn — the number of days in each Berland month, mm — the number of months. Thus, a table cell corresponds to a day and a month of the Berland's year. Each cell will contain either 1, or -1, which means the state's gains in a particular month, on a particular day. 1 corresponds to profits, -1 corresponds to losses. It turned out important for successful development to analyze the data on the state of the economy of the previous year, however when the treasurers referred to the archives to retrieve the data, it turned out that the table had been substantially damaged. In some table cells the number values had faded and were impossible to be deciphered. It is known that the number of cells in which the data had been preserved is strictly less than max(n,m)max(n,m) . However, there is additional information — the product of the numbers in each line and column equaled -1. Your task is to find out how many different tables may conform to the preserved data. As the answer to the task can be quite large, you have to find it modulo pp .

输入格式

The first line contains integers nn and mm ( 1<=n,m<=10001<=n,m<=1000 ). The second line contains the integer kk ( 0<=k<max(n,m) ) — the number of cells in which the data had been preserved. The next kk lines contain the data on the state of the table in the preserved cells. Each line is of the form " aa bb cc ", where aa ( 1<=a<=n1<=a<=n ) — the number of the table row, bb ( 1<=b<=m1<=b<=m ) — the number of the column, cc — the value containing in the cell (1 or -1). They are numbered starting from 11 . It is guaranteed that no two lines with same aa and bb values exist. The last line contains an integer pp ( 2<=p<=109+72<=p<=10^{9}+7 ).

输出格式

Print the number of different tables that could conform to the preserved data modulo pp .

输入输出样例

  • 输入#1

    2 2
    0
    100
    

    输出#1

    2
    
  • 输入#2

    2 2
    1
    1 1 -1
    100
    

    输出#2

    1
    
首页