using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; //using nint=System.Int32; static class Program{ const int mod=(int)1e9+7; static void Main(){ Sc sc=new Sc(); var s=sc.Ia; var h=new Mint[s[0]+1]; var ba=new bool[s[0]+1]; for(int i = 1;i<=s[0];i++) {h[i]=1;} Uf2 uf2=new Uf2(s[0]+1); var g=Mint.Mi(2); for(int i = 0;iuf2.Size(b)){ p=h[a]; uf2.Scan(uf2.Root(b),uf2.Size(b),x=>{ba[x]=true;}); } else if(uf2.Size(a){ba[x]=true;}); } else{ p=h[a]*g; } uf2.Union(a,b); h[uf2.Root(a)]=p; } } for(int i = 1;i<=s[0];i++) { if(!ba[i]){h[i]=h[uf2.Root(i)];} } for(int i = 1;i<=s[0];i++) { if(ba[i]){h[i]=0;} } Console.WriteLine("{0}",string.Join("\n",h.Skip(1))); } } public struct Mint{ const int mod=(int)1e9+7; private long d; public Mint(long d){this.d=d;} public static implicit operator Mint(long d){return new Mint(d%mod);} public static explicit operator long(Mint d){return d.d;} public override string ToString(){return d.ToString();} public static Mint operator+(Mint a,long b){a.d=(a.d+b)%mod;return a;} public static Mint operator+(Mint a,Mint b){a.d=(a.d+b.d)%mod;return a;} public static Mint operator-(Mint a,long b){a.d=(mod+a.d-b)%mod;return a;} public static Mint operator-(Mint a,Mint b){a.d=(mod+a.d-b.d)%mod;return a;} public static Mint operator*(Mint a,long b){a.d=(a.d*b)%mod;return a;} public static Mint operator*(Mint a,Mint b){a.d=(a.d*b.d)%mod;return a;} public static Mint operator/(Mint a,long b){a.d=(a.d*Mi(b))%mod;return a;} public static Mint operator/(Mint a,Mint b){a.d=(a.d*Mi(b.d))%mod;return a;} public static bool operator==(Mint a,long b){return (long)a==b;} public static bool operator!=(Mint a,long b){return (long)a!=b;} public override bool Equals(object obj){return false;} public override int GetHashCode(){return 0;} public static long Mi(long a){ a=(a+mod)%mod; long b=mod,u=1,v=0; while(b>0){ long t=a/b; a-=t*b;(a,b)=(b,a); u-=t*v;(u,v)=(v,u); } u%=mod; if(u<0){u+=mod;} return u%mod; } } public class Uf2{ public class Nd{ public int n; public Nd ne; public Nd(int n){this.n=n;} } private int[] arr,hi; public Nd[] f,l; public int all; public Uf2(int n){ arr=new int[n]; hi=new int[n]; f=new Nd[n]; l=new Nd[n]; all=n; for(int i=0;iarr[b]){(a,b)=(b,a);} arr[a]+=arr[b]; hi[a]=Max(hi[a],hi[b]+1); arr[b]=a; all--; l[a].ne=f[b]; l[a]=l[b]; return true; } return false; } public bool Same(int a,int b){return Root(a)==Root(b);} public int Size(int a){return -arr[Root(a)];} public int Root(int a){return arr[a]<0?a:arr[a]=Root(arr[a]);} public void Scan(int a,int m,Action fu){ var e=f[a]; for(int j = 0;j(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]));} public (T,T,T) Tp3(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} public (T1,T1,T2) Tp3(){var s=Console.ReadLine().Split();return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} private T Ct(string s){return (T)Convert.ChangeType(s,typeof(T));} }