#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; using ull = unsigned long long; constexpr ll mod=1e9+7; int n; ll res=0; vector g[1001000]; int d[1001000]; ll dp[1001000]; void dfs(int s){ d[s]=1; for(int t:g[s]){ dfs(t); d[s]+=d[t]; (dp[s]+=dp[t])%=mod; } dp[s]+=d[s]-1; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin >> n; vector v(n,true); for(int i=1;i> a >> b; a--; b--; g[a].push_back(b); v[b]=false; } int s; for(int i=0;i