fork(1) download
  1. #include <bits/stdc++.h>
  2. // #include "stdafx.h"
  3. // #pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS
  4. using namespace std;
  5. #define gc getchar_unlocked
  6. #define fo(i,n) for(i=0;i<n;i++)
  7. #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
  8. #define ll long long
  9. #define si(x) scanf("%d",&x)
  10. #define sl(x) scanf("%lld",&x)
  11. #define ss(s) scanf("%s",s)
  12. #define pi(x) printf("%d\n",x)
  13. #define pl(x) printf("%lld\n",x)
  14. #define ps(s) printf("%s\n",s)
  15. #define deb(x) cout << #x << "=" << x << endl
  16. #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
  17. #define pb push_back
  18. #define mp make_pair
  19. #define F first
  20. #define S second
  21. #define all(x) x.begin(), x.end()
  22. #define clr(x) memset(x, 0, sizeof(x))
  23. #define sortall(x) sort(all(x))
  24. #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
  25. #define PI 3.1415926535897932384626
  26. typedef pair<int, int> pii;
  27. typedef pair<ll, ll> pl;
  28. typedef vector<int> vi;
  29. typedef vector<ll> vl;
  30. typedef vector<pii> vpii;
  31. typedef vector<pl> vpl;
  32. typedef vector<vi> vvi;
  33. typedef vector<vl> vvl;
  34. int mpow(int base, int exp);
  35. void ipgraph(int m);
  36. void dfs(int u, int par);
  37. const int mod = 998244353;
  38. const int N = 3e5, M = N;
  39. //=======================
  40.  
  41. vi g[N];
  42. int a[N], col[N];
  43. int n, m, valid;
  44.  
  45. void color(int u, int p, int c)
  46. {
  47. col[u] = c;
  48. int nc = 3-c;
  49. for(int v: g[u])
  50. {
  51. if(col[v]){
  52. if(col[v] != nc) valid = false;
  53. }
  54. else color(v, u, 3-c);
  55. }
  56. }
  57.  
  58. void solve()
  59. {
  60. int i, x, y;
  61. cin >> n >> m;
  62. fo(i, n) g[i].clear(), col[i] = 0;
  63. valid = true;
  64.  
  65. while(m--)
  66. {
  67. cin >> x >> y; x--, y--;
  68. g[x].pb(y);
  69. g[y].pb(x);
  70. }
  71. //This won't get AC in the case
  72. //where the graph will be disconnected
  73. //but the overall idea is this...
  74. color(0, -1, 1);
  75. if(!valid) cout << 0 << endl;
  76. else {
  77. ll ans = 0;
  78. int cnt = 0;
  79. fo(i, n) cnt += col[i] == 1;
  80. ans = (mpow(2, cnt) + mpow(2, n-cnt)) % mod;
  81. cout << ans << endl;
  82. }
  83. }
  84.  
  85. int main()
  86. {
  87. int t;
  88. //freopen("input.txt", "r", stdin);
  89. //freopen("output.txt", "w", stdout);
  90. ios_base::sync_with_stdio(false);
  91. cin.tie(NULL);
  92. int i,n,k,j;
  93. cin >> t;
  94. while(t--) solve();
  95. return 0;
  96. }
  97.  
  98. int mpow(int base, int exp) {
  99. base %= mod;
  100. int result = 1;
  101. while (exp > 0) {
  102. if (exp & 1) result = ((ll)result * base) % mod;
  103. base = ((ll)base * base) % mod;
  104. exp >>= 1;
  105. }
  106. return result;
  107. }
  108.  
Success #stdin #stdout 0s 24608KB
stdin
2
2 1
1 2
4 6
1 2
1 3
1 4
2 3
2 4
3 4
stdout
4
0