77752024-01-11 09:36:40gortomiTrükkcpp17Accepted 60/6037ms6912 KiB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
const int MOD = 1e9 + 7;
vector<int> vis;
bool dfs(int v)
{
    for(auto x : g[v])
    {
        if(vis[x] == -1)
        {
            vis[x] = 1 - vis[v];
            if(!dfs(x)) return 0;
        }
        else if(vis[x] != 1 - vis[v]) return 0;
    }
    return 1;
}
void solve()
{
    int n, m;
    cin >> n >> m;
    g.assign(n + 1, {});
    vis.assign(n + 1, -1);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    long long ans = 1;
    for(int i = 0; i <= n; i++)
    {
        if(vis[i] == -1)
        {
            vis[i] = 0;
            if(!dfs(i))
            {
                cout << "0\n";
                return;
            }
            if(i != 0) ans *= 2;
            ans %= MOD;
        }
    }
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) solve();
}
SubtaskSumTestVerdictTimeMemory
base60/60
1Accepted0/03ms1824 KiB
2Accepted0/018ms3784 KiB
3Accepted3/33ms2144 KiB
4Accepted3/33ms2100 KiB
5Accepted3/33ms2232 KiB
6Accepted3/33ms2440 KiB
7Accepted2/235ms5420 KiB
8Accepted2/232ms5640 KiB
9Accepted2/232ms5784 KiB
10Accepted2/235ms5620 KiB
11Accepted2/234ms5744 KiB
12Accepted2/232ms5976 KiB
13Accepted2/232ms6536 KiB
14Accepted2/232ms6688 KiB
15Accepted2/232ms6644 KiB
16Accepted2/232ms6824 KiB
17Accepted2/232ms6680 KiB
18Accepted2/232ms6680 KiB
19Accepted2/237ms6156 KiB
20Accepted2/234ms6188 KiB
21Accepted2/235ms6160 KiB
22Accepted2/232ms6284 KiB
23Accepted2/232ms6784 KiB
24Accepted2/232ms6760 KiB
25Accepted2/232ms6912 KiB
26Accepted2/232ms6888 KiB
27Accepted2/234ms6368 KiB
28Accepted2/230ms5928 KiB
29Accepted2/217ms5724 KiB
30Accepted2/217ms5920 KiB