1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| #include <iostream> #include <algorithm> #include <math.h> #include <cstring> using namespace std; typedef long long ll; const ll mod = 998244353; vector<int>G[300005]; int dln[300005], d[300005]; int cnt ; void dfs(int now,int p) { dln[now] = dln[p] + 1; for(int i = 0; i < G[now].size(); ++i) { int v = G[now][i]; if(v == p) continue; if(dln[v] != 0){ if(dln[v] < dln[now]) d[++cnt] = dln[now] - dln[v] + 1; } else dfs(v, now); } }
ll pow(ll a, ll b, ll mod) { ll ans = 1; while(b) { if(b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans % mod; }
int main() { int n, m ,u, v; cin >> n >> m; cnt = 0; memset(dln, 0, sizeof(dln)); for(int i = 1 ; i <= m; ++i) { scanf("%d %d",&u,&v); G[u].push_back(v); G[v].push_back(u); } dfs(1, 0); int edge = m; for(int i = 1; i <= cnt; ++i) { edge -= d[i]; } long long ans = pow(2, edge, mod); for(int i = 1; i <= cnt; ++i) { ll num = pow(2, d[i], mod); ll num1 = (num - 1 + mod) % mod; ans = (ans * num1) % mod; } cout << ans << '\n';
}
|