#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using pint = pair; struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #include using mint = atcoder::modint1000000007; // UnionFind Tree (0-indexed), based on size of each disjoint set struct UnionFind { std::vector par, cou; UnionFind(int N = 0) : par(N), cou(N, 1) { iota(par.begin(), par.end(), 0); } int find(int x) { return (par[x] == x) ? x : (par[x] = find(par[x])); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return false; if (cou[x] < cou[y]) std::swap(x, y); par[y] = x, cou[x] += cou[y]; return true; } int count(int x) { return cou[find(x)]; } bool same(int x, int y) { return find(x) == find(y); } }; int main() { int N, M; cin >> N >> M; vector to(N); UnionFind uf(N); vector fi(N); vector sz(N, 1); iota(fi.begin(), fi.end(), 0); sz.reserve(N + M); fi.reserve(N + M); while (M--) { int a, b; cin >> a >> b; a--, b--; a = uf.find(a), b = uf.find(b); if (uf.unite(a, b)) { to.emplace_back(fi[a], fi[b]); sz.push_back(uf.count(a)); fi[uf.find(a)] = int(to.size()) - 1; } } mint inv2 = 500000004; vector prob(sz.size(), 1); IFOR(i, N, sz.size()) { auto [a, b] = to[i]; if (sz[a] < sz[b]) swap(a, b); if (sz[a] == sz[b]) prob[a] = prob[b] = prob[i] * inv2; else prob[a] = prob[i], prob[b] = 0; } REP(i, N) cout << prob[i].val() << '\n'; }