#include "bits/stdc++.h" using namespace std; using ll=long long; using vll=vector< ll>; using vvll=vector< vll>; using vvvll=vector< vvll>; using vvvvll=vector; using dd=double; using vdd=vector< dd>; using vvdd=vector< vdd>; using pll=pair; using tll=tuple; using qll=tuple; constexpr ll INF = 1LL << 60; struct Fast{ Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout<::max_digits10); } } fast; #define REPS(i, S, E) for (ll i = (S); i <= (E); i++) #define REP(i, N) REPS(i, 0, (N)-1) #define DEPS(i, S, E) for (ll i = (E); i >= (S); i--) #define DEP(i, N) DEPS(i, 0, (N)-1) #define rep(i, S, E) for (ll i = (S); i <= (E); i++) #define dep(i, E, S) for (ll i = (E); i >= (S); i--) #define each(e, v) for (auto&& e : v) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; } template inline T MaxE(vector&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; } template inline T MinE(vector&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; } template inline T MaxE(vector &v) { return MaxE(v,0,(ll)v.size()-1); } template inline T MinE(vector &v) { return MinE(v,0,(ll)v.size()-1); } template inline T Sum(vector &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; } template inline T Sum(vector &v) { return Sum(v,0,v.size()-1); } template inline ll sz(T &v){ return (ll)v.size(); } inline ll CEIL(ll a,ll b){ return (a<0) ? -(-a/b) : (a+b-1)/b; } inline ll FLOOR(ll a,ll b){ return -CEIL(-a,b); } template struct mll_{ ll val; mll_(ll v = 0): val(v % MOD){ if (val < 0) val += MOD; } mll_ operator - () const { return -val; } mll_ operator + (const mll_ &b) const { return val + b.val; } mll_ operator - (const mll_ &b) const { return val - b.val; } mll_ operator * (const mll_ &b) const { return val * b.val; } mll_ operator / (const mll_ &b) const { return mll_(*this) /= b; } mll_ operator + (ll b) const { return *this + mll_(b); } mll_ operator - (ll b) const { return *this - mll_(b); } mll_ operator * (ll b) const { return *this * mll_(b); } friend mll_ operator + (ll a,const mll_ &b) { return b + a; } friend mll_ operator - (ll a,const mll_ &b) { return -b + a; } friend mll_ operator * (ll a,const mll_ &b) { return b * a; } friend mll_ operator / (ll a,const mll_ &b) { return mll_(a)/b; } mll_ &operator += (const mll_ &b) { val=(val+b.val)%MOD; return *this; } mll_ &operator -= (const mll_ &b) { val=(val+MOD-b.val)%MOD; return *this; } mll_ &operator *= (const mll_ &b) { val=(val*b.val)%MOD; return *this; } mll_ &operator /= (const mll_ &b) { ll c=b.val,d=MOD,u=1,v=0; while (d){ ll t = c / d; c -= t * d; swap(c,d); u -= t * v; swap(u,v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } mll_ &operator += (ll b) { return *this += mll_(b); } mll_ &operator -= (ll b) { return *this -= mll_(b); } mll_ &operator *= (ll b) { return *this *= mll_(b); } mll_ &operator /= (ll b) { return *this /= mll_(b); } bool operator == (const mll_ &b) const { return val == b.val; } bool operator != (const mll_ &b) const { return val != b.val; } bool operator == (ll b) const { return *this == mll_(b); } bool operator != (ll b) const { return *this != mll_(b); } friend bool operator == (ll a,const mll_ &b) { return mll_(a) == b.val; } friend bool operator != (ll a,const mll_ &b) { return mll_(a) != b.val; } friend ostream &operator << (ostream &os,const mll_ &a) { return os << a.val; } friend istream &operator >> (istream &is,mll_ &a) { return is >> a.val; } static mll_ Combination(ll a,ll b){ chmin(b,a-b); if (b<0) return mll_(0); mll_ c = 1; rep(i,0,b-1) c *= a-i; rep(i,0,b-1) c /= i+1; return c; } }; using mll = mll_<998244353LL>; using vmll = std::vector; using vvmll = std::vector; using vvvmll = std::vector; using vvvvmll = std::vector; #if 0 #include using namespace atcoder; #endif vvll cinGraph(ll nodeNum,ll edgeNum,bool isDirected){//無向false、有向true vvll to(nodeNum); rep(i,0,edgeNum-1){ ll v,u; cin >> v >> u; v--; u--; to[v].push_back(u); if (!isDirected) to[u].push_back(v); } return move(to); } ll N,M; vvll to; vll seen; void dfs(ll v,ll id){ seen[v]=id; each(u,to[v]){ if (seen[u]==-1) dfs(u,id); } } mll det(vvmll &mat){ ll n=(ll)mat.size(); mll prod=1; rep(i,0,n-1){ prod*=mat[i][i]; mll inv=mll(1)/mat[i][i]; rep(j,i,n-1) mat[i][j]*=inv; rep(ii,i+1,n-1)dep(j,n-1,i) mat[ii][j]-=mat[ii][i]*mat[i][j]; } return prod; } mll countST(ll id){ unordered_map mp; vll tr; ll idx=0; rep(v,0,N-1){ if (seen[v]!=id) continue; mp[v]=idx++; tr.push_back(v); } ll mm=(ll)tr.size(); if (mm==1)return mll(1); vvmll L(mm-1,vmll(mm-1));//ラプラシアン行列の端を削ったもの rep(i,0,mm-2){ ll v=tr[i]; each(u,to[v]){ ll idx=mp[u]; if (idx==mm-1)continue; L[i][idx]=-1; } L[i][i]=(ll)to[v].size(); } return det(L); } void solve() { cin >> N >> M; to = cinGraph(N,M,false); seen.resize(N,-1); ll idnm=0; rep(v,0,N-1){ if (seen[v]!=-1)continue; dfs(v,idnm++); } if (idnm==1){ cout << 0 << '\n'; cout << countST(0) << '\n'; return; } vll ccsize(idnm); each(e,seen) ccsize[e]++; sort(ALL(ccsize)); ll fuben=0; { ll tmp=ccsize[idnm-1]+ccsize[idnm-2]; fuben+=(N-tmp)*tmp; dep(i,idnm-3,0) fuben+=(N-ccsize[i])*ccsize[i]; } ll x=-1,y=-1; ll p=0,q=0; while (!ccsize.empty()){ ll s=ccsize.back(); ccsize.pop_back(); if (x==-1) x=s; if (x==s){ p++; continue; } if (y==-1) y=s; if (y==s){ q++; continue; } break; } mll ans=1; rep(id,0,idnm-1) ans*=countST(id); if (p>=2){ ans*=x*x*p*(p-1)/2; } else{ ans*=x*y*q; } cout << fuben << '\n'; cout << ans << '\n'; } int main(){ #if 1 solve(); #else ll t; cin >> t; rep(i, 0, t-1){ solve(); } #endif return 0; }