213262026-01-12 18:28:47algoproTrükkcpp17Wrong answer 0/6079ms2244 KiB
// UUID: e8049b2a-c53c-4e03-bef6-3c5118af258f
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;

vector<vector<int>> adj;
vector<bool> vis;
vector<int> parent;
vector<int> d;
const ll MOD = 1e9 + 7;

bool dfs(int v){
    vis[v] = true;
    d[v] = 1;
    for(auto x : adj[v]){
        if(!vis[x]){
            parent[x] = v;
            dfs(x);
        }else if(parent[v] != x){
            if((d[v] - d[x])%2 == 0){
                return false;
            }
        }
    }
    return true;
}

int main() {
	int t;
    cin >> t;
    while(t--){
        int n, k;
        cin >> n >> k;
        adj.assign(n+1, vector<int>());
        vis.assign(n+1, false);
        parent.assign(n+1, 0);
        d.assign(n+1, 0);
        for(int i=0;i<k;i++){
            int l, r;
            cin >> l >> r;
            adj[r].push_back(l-1);
            adj[l-1].push_back(r);
        }
        int components = 0;
        ll ans = 1;
        for(int i=1;i<=n;i++){
            if(!vis[i]){
                components++;
                parent[i] = i;
                if(!dfs(i)){
                    ans = 0;
                }
            }
        }
        for(int i=0;i<components-1;i++){
            ans *= 2;
            ans %= MOD;
        }
        cout << ans << '\n';

    }
}

/*
0 0 0:
0 0 1
0 1 0
1 0 0
1 1 1


*/
SubtaskSumTestVerdictTimeMemory
base0/60
1Accepted0/01ms316 KiB
2Wrong answer0/037ms1332 KiB
3Wrong answer0/31ms316 KiB
4Wrong answer0/31ms508 KiB
5Wrong answer0/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/278ms1960 KiB
8Wrong answer0/278ms1988 KiB
9Wrong answer0/278ms2056 KiB
10Wrong answer0/278ms1792 KiB
11Wrong answer0/278ms1872 KiB
12Wrong answer0/278ms1784 KiB
13Wrong answer0/272ms2100 KiB
14Wrong answer0/272ms2220 KiB
15Wrong answer0/272ms2096 KiB
16Wrong answer0/272ms2216 KiB
17Wrong answer0/271ms2244 KiB
18Wrong answer0/272ms2096 KiB
19Wrong answer0/278ms2132 KiB
20Wrong answer0/278ms2104 KiB
21Wrong answer0/278ms2100 KiB
22Wrong answer0/279ms1988 KiB
23Wrong answer0/278ms2100 KiB
24Wrong answer0/278ms2172 KiB
25Wrong answer0/278ms2192 KiB
26Wrong answer0/272ms2100 KiB
27Wrong answer0/278ms2100 KiB
28Wrong answer0/274ms1588 KiB
29Wrong answer0/237ms1452 KiB
30Wrong answer0/235ms1660 KiB