Irreversible Reactions

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Life is ephemeral. What is done sometimes cannot be irreversible. In terms of this, chemical reaction networks are similar to life.

For brevity, we model a chemical reaction network as follows. There are NN states in a chemical reaction network. The reaction starts with the state SS. MM distinct pairs (u_iu\_i, v_iv\_i) of states have a relation such that u_iu\_i can be transited to v_iv\_i. For each unit of time, a state is transited to other states if there is at least one state that can be transited from the state. If there are no such states, the state does not change. If there are two or more states to which the current state can be transited, the next state is selected at uniformly random from these states.

In an experiment of the chemical reaction network, we stop the experiment when the current state does not change. In addition, after transitions, it might reach a state from which it's impossible to return back to SS by repeating transitions. In such cases we also stop the experiment. Your task as a bioinformatics researcher is to write a program to compute the expected time until we stop the experiment. If the expected time is infinite, output 1-1 instead.

A more precise description of the experiment termination criteria is the following. If there are no states that can be transited from the current state, we stop the experiment immediately. Otherwise, the experiment does not stop, if it is possible to return back to SS from the current state by repeating zero or more transitions. In other words, the state SS itself is always considered as a state that can return to SS in this case.

입력

The input consists of a single test case in the format below.

NN MM SS

u_1u\_1 v_1v\_1

\vdots

u_Mu\_M v_Mv\_M

The first line contains three integers NN (2N2002 \le N \le 200), MM (1Mmin(N(N1)1000)1 \le M \le \min{(N(N-1)1000)}), SS (1SN1 \le S \le N). NN is the number of states in a chemical reaction network. MM is the number of transitions between states. SS is the initial state. The ii-th of the following MM lines represents the ii-th transition, which means a state u_iu\_i can be transited to v_iv\_i (1u_i,v_iN1 \le u\_i, v\_i \le N, u_iv_iu\_i \ne v\_i). Note that it does not necessarily imply v_iv\_i can be transitioned to u_iu\_i. It is guaranteed that the pairs u_iu\_i and v_iv\_i are distinct. That is, for 1i<jM1 \le i < j \le M, either u_iu_ju\_i \ne u\_j or v_iv_jv\_i \ne v\_j holds.

출력

Output the expected time to reach one of the states from which it's impossible to return back to the initial state SS. The expected time can be huge, thus outputs the expected time modulo 109+710^9 + 7. More precisely, if it is finite, the expected time can be represented as an irreducible fraction b/ab/a, and you should output the minimum non-negative integer xx which satisfies axbmod109+7ax \equiv b \bmod {10^9 + 7}. You may assume that such xx exists for the given input.

If the expected time is infinity, output 1-1 instead.