45682023-03-29 22:53:31Valaki2Trükkcpp14Wrong answer 0/6039ms6968 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int mod = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > g(1 + n);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        g[a].pb(b);
        g[b].pb(a);
    }
    vector<int> which(1 + n, -1);
    int total = 0, comp_cnt = 0;
    for(int i = 0; i <= n; i++) {
        if(which[i] == -1) {
            if(g[i].size() > 0) {
                comp_cnt++;
                which[i] = 0;
                for(int j : g[i]) {
                    which[j] = 1 - which[i];
                }
            }
        } else {
            for(int j : g[i]) {
                if(which[j] == which[i]) {
                    cout << "0\n";
                    return;
                }
                if(which[j] == -1) {
                    which[j] = 1 - which[i];
                }
            }
        }
    }
    for(int i = 0; i <= n; i++) {
        if(which[i] != -1) {
            total++;
        }
    }
    int ans_exponent = n - total + comp_cnt;
    int ans = 1;
    for(int i = 0; i < ans_exponent; i++) {
        ans *= 2;
        ans %= mod;
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/60
1Accepted0/03ms1828 KiB
2Wrong answer0/019ms3552 KiB
3Wrong answer0/33ms2264 KiB
4Wrong answer0/32ms2320 KiB
5Wrong answer0/33ms2544 KiB
6Wrong answer0/32ms2532 KiB
7Wrong answer0/237ms5360 KiB
8Wrong answer0/239ms5568 KiB
9Wrong answer0/239ms5532 KiB
10Wrong answer0/237ms5652 KiB
11Wrong answer0/237ms5628 KiB
12Wrong answer0/237ms5848 KiB
13Wrong answer0/229ms5712 KiB
14Wrong answer0/229ms6012 KiB
15Wrong answer0/228ms6072 KiB
16Wrong answer0/229ms6300 KiB
17Wrong answer0/230ms6152 KiB
18Wrong answer0/229ms6124 KiB
19Wrong answer0/239ms6176 KiB
20Wrong answer0/239ms6192 KiB
21Wrong answer0/239ms6412 KiB
22Wrong answer0/237ms6296 KiB
23Wrong answer0/237ms6376 KiB
24Wrong answer0/237ms6464 KiB
25Wrong answer0/237ms6636 KiB
26Wrong answer0/229ms6796 KiB
27Wrong answer0/239ms6968 KiB
28Wrong answer0/235ms6840 KiB
29Wrong answer0/216ms6112 KiB
30Wrong answer0/216ms6120 KiB