#include<cstdint>#include<istream>#include<vector>usingll=longlong;classruntime_modint{usingu64=std::uint_fast64_t;staticu64&mod(){staticu64mod_=0;returnmod_;}public:u64a;runtime_modint(constu64x=0):a(x%get_mod()){}u64&value()noexcept{returna;}constu64&value()constnoexcept{returna;}inlineconstexproperatorll()constnoexcept{returna;}runtime_modintoperator+(construntime_modintrhs)const{returnruntime_modint(*this)+=rhs;}runtime_modintoperator-(construntime_modintrhs)const{returnruntime_modint(*this)-=rhs;}runtime_modintoperator*(construntime_modintrhs)const{returnruntime_modint(*this)*=rhs;}runtime_modintoperator/(construntime_modintrhs)const{returnruntime_modint(*this)/=rhs;}runtime_modint&operator+=(construntime_modintrhs){a+=rhs.a;if(a>=get_mod()){a-=get_mod();}return*this;}runtime_modint&operator-=(construntime_modintrhs){if(a<rhs.a){a+=get_mod();}a-=rhs.a;return*this;}runtime_modint&operator*=(construntime_modintrhs){a=a*rhs.a%get_mod();return*this;}runtime_modint&operator/=(runtime_modintrhs){u64exp=get_mod()-2;while(exp){if(exp%2){*this*=rhs;}rhs*=rhs;exp/=2;}return*this;}template<classT>inlineconstexprruntime_modint&operator+=(Tx)noexcept{returnoperator+=(runtime_modint(x));}template<classT>inlineconstexprruntime_modint&operator+(Tx)noexcept{returnruntime_modint(*this)+=x;}template<classT>inlineconstexprruntime_modint&operator-=(Tx)noexcept{returnoperator-=(runtime_modint(x));}template<classT>inlineconstexprruntime_modint&operator-(Tx)noexcept{returnruntime_modint(*this)-=x;}template<classT>inlineconstexprruntime_modint&operator*=(Tx)noexcept{returnoperator*=(runtime_modint(x));}template<classT>inlineconstexprruntime_modint&operator*(Tx)noexcept{returnruntime_modint(*this)*=x;}template<classT>inlineconstexprruntime_modint&operator/=(Tx)noexcept{returnoperator/=(runtime_modint(x));}template<classT>inlineconstexprruntime_modint&operator/(Tx)noexcept{returnruntime_modint(*this)/=x;}staticvoidset_mod(constu64x){mod()=x;}staticu64get_mod(){returnmod();}};lln,m;boolused[100000];std::vector<std::pair<ll,runtime_modint>>G[100000];runtime_modintdfs(llx){used[x]=true;boolend=true;runtime_modintres=1;for(auto&p:G[x]){if(used[p.first]==true)continue;end=false;if(p.second!=0){res*=p.second;}else{p.second=dfs(p.first);// cout << x MM p.fi MM p.se << endl;
res*=p.second;}}used[x]=false;returnres+1;}