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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5,P = 998244353; inline void Plus(int &x,const int &y) { x += y;if(x >= P) x -= P;} int n,m; vector<pair<int,int> > G[N];
namespace Brute { const int N = 15; int col[N],ton[3]; int now; bool vis[N]; bool Check(int x) { vis[x] = 1; for(auto [y,i] : G[x]) { if(vis[y]) continue; now += !(ton[col[i]]++); if(now == 3 || Check(y)) return true; now -= !(--ton[col[i]]); } return vis[x] = 0; } int ans; void Dfs(int x) { if(x > m) { now = 0; for(int i = 1;i <= n;i++) if(Check(i)) { memset(ton,0,sizeof ton); memset(vis,0,sizeof vis); ++ans;break; } return; } col[x] = 0;Dfs(x + 1); col[x] = 1;Dfs(x + 1); col[x] = 2;Dfs(x + 1); } }
int dfn[N],low[N],top,stk[N]; int dego[N];
void tarjan(int x,int from) { dfn[x] = low[x] = ++dfn[0]; stk[++top] = x; for(auto [y,i] : G[x]) { if(i == from) continue; if(!dfn[y]) { tarjan(y,i); low[x] = min(low[x],low[y]); if(low[y] >= dfn[x]) { while(stk[top] != y) ++dego[stk[top--]]; ++dego[y];++dego[x];--top; } } else low[x] = min(low[x],dfn[y]); } } int Pow2[N],Pow3[N]; inline int F(int x) { if(x <= 2) return 0; return (Pow3[x] - 3ll * Pow2[x] % P + 3 + P) % P; } int main() { cin >> n >> m; for(int i = 1,u,v;i <= m;i++) cin >> u >> v,G[u].emplace_back(v,i),G[v].emplace_back(u,i); if(n <= 4) { Brute::Dfs(1);printf("%d\n",Brute::ans);return 0;} Pow2[0] = Pow3[0] = 1; for(int i = 1;i <= m;i++) Pow2[i] = (Pow2[i - 1] + Pow2[i - 1]) % P, Pow3[i] = 3ll * Pow3[i - 1] % P; int ans = 0; for(int u = 1;u <= n;u++) for(auto [v,i] : G[u]) { if(G[u].size() == 2 && G[v].size() == 2 && u < v) { int w = (G[u][0].first == v) ? G[u][1].first : G[u][0].first; if(w == ((G[v][0].first == u) ? G[v][1].first : G[v][0].first)) Plus(ans,6); } } tarjan(1,0); for(int i = 1;i <= n;i++) Plus(ans,F(dego[i])); ans = (F(m) + P - ans) % P; cout << ans << endl; return 0; }
|