27732023-01-23 17:09:25CattTrükkcpp17Wrong answer 18/6083ms7180 KiB
#include <bits/stdc++.h>
using namespace std;
#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using ll = long long;

const int maxN = 2e5 + 5;
const int MOD = 1e9 + 7;


ll power(ll a, ll b) {
    ll res = 1;
    while(b > 0) {
        if(b % 2) res = (res * a) % MOD;
        a = (a*a) % MOD;
        b /= 2;
    }
    return res;
}


vector<vector<int> > g;
vector<int> c;

bool dfs(int x) {
    bool ret = 0;
    for(int sz : g[x]) {
        if(c[sz] == -1) {
            c[sz] = 1 - c[x];
            ret |= dfs(sz);
        }
        else if(c[sz] == c[x]) ret = 1;
    }

    return ret;
}

int main() {
    int t;
    cin >> t;
    while(t--)
    {
        int n,m;
        cin >> n >> m;

        g.clear();
        g.resize(n+1);
        c.assign(n+1, -1);

        for(int i = 0; i < m; i++) {
            int x,y;
            cin >> x >> y;
            x--;
            g[x].push_back(y);
            g[y].push_back(x);
        }

        int comp = 0;
        bool b = 0;
        for(int i = 0; i <= n; i++) {
            if(c[i] == -1) {
                c[i] = 0;
                b |= dfs(i);
                comp++;

                if(b) {
                    cout << i << endl;
                    break;
                }
            }
        }

        if(b) cout <<"0\n";
        else {
            cout << power(2, comp-1) << "\n";
        }
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/60
1Wrong answer0/03ms1880 KiB
2Accepted0/041ms3464 KiB
3Accepted3/32ms2192 KiB
4Wrong answer0/32ms2316 KiB
5Accepted3/32ms2524 KiB
6Wrong answer0/32ms2728 KiB
7Accepted2/282ms5192 KiB
8Wrong answer0/281ms5396 KiB
9Wrong answer0/283ms5340 KiB
10Accepted2/281ms5476 KiB
11Wrong answer0/281ms5680 KiB
12Wrong answer0/282ms6184 KiB
13Accepted2/271ms5244 KiB
14Wrong answer0/271ms5376 KiB
15Wrong answer0/271ms5452 KiB
16Accepted2/271ms5576 KiB
17Wrong answer0/271ms5576 KiB
18Wrong answer0/271ms5900 KiB
19Accepted2/281ms6888 KiB
20Wrong answer0/279ms6964 KiB
21Wrong answer0/281ms7100 KiB
22Wrong answer0/279ms6920 KiB
23Wrong answer0/279ms6776 KiB
24Wrong answer0/279ms6792 KiB
25Wrong answer0/279ms6848 KiB
26Wrong answer0/271ms6580 KiB
27Wrong answer0/282ms7180 KiB
28Wrong answer0/276ms6528 KiB
29Accepted2/235ms6008 KiB
30Wrong answer0/235ms6008 KiB