题目描述
#include#include #define N 100002 using namespace std; typedef long long ll; const int mod=1e9+7; int n,m,tot,head[N],xx,yy; bool vis[N]; ll dp[N],ans=1,du[N]; struct edge{int n,to; }e[N<<1]; inline int rd(){int x=0;char c=getchar();bool f=0;while(!isdigit(c)){ if(c=='-')f=1;c=getchar();}while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}return f?-x:x; } inline ll power(ll x,ll y){ll ans=1;while(y){ if(y&1)ans=ans*x%mod;x=x*x%mod;y>>=1;}return ans; } inline void add(int u,int v){e[++tot].n=head[u];e[tot].to=v;head[u]=tot; } void dfs(int u){if(vis[u])return;vis[u]=1;if(u==xx){dp[u]=ans*power(du[u],mod-2)%mod;return;}for(int i=head[u];i;i=e[i].n){int v=e[i].to;dfs(v);(dp[u]+=dp[v])%=mod;}dp[u]=dp[u]*power(du[u],mod-2)%mod; } int main(){n=rd();m=rd();xx=rd();yy=rd();int x,y;for(int i=1;i<=m;++i){x=rd();y=rd();add(x,y);du[y]++;}du[yy]++;ans=1;for(int i=1;i<=n;++i)if(du[i])ans=ans*du[i]%mod;if(yy!=1)dfs(yy); cout<<(ans-dp[yy]+mod)%mod;return 0; }