230472026-01-16 11:12:22algoproTrükkcpp17Wrong answer 2/6039ms3976 KiB
// UUID: 2b66be49-8967-47a7-a9ab-d480ac0a9bba
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define fs first
#define sc second
#define pb push_back
#define pll pair<ll, ll>
#define vll vector<ll>
#define v2ll vector<vll>
#define pqll priority_queue<ll>

const ll mod = 1e9+7;
const ll inf = LONG_LONG_MAX;

ll n, k;
vector<bool> vis, c;
v2ll g;
bool possible;

void dfs(ll p) {
    vis[p] = 1;
    for (ll i : g[p]) {
        if (!vis[i]) {
            c[i] = 1-c[p];
            dfs(i);
        } else if (c[p] == c[i])
            possible = false;
    }
}

void solve()
{
    cin >> n >> k;
    g.resize(n+1); vis.resize(n+1); c.resize(n+1);
    possible = true;
    for (ll i = 0; i < k; i++) {
        ll a, b;
        cin >> a >> b;
        g[a-1].pb(b);
        g[b].pb(a-1);
    }
    ll ans = 0;
    dfs(0);
    if (possible) ans++;
    for (ll i = 1; i <= n; i++) {
        if (!possible) break;
        if (!vis[i]) {
            dfs(i);
            if (possible) ans *= 2;
            else ans = 0;
            ans %= mod;
        }
    }
    cout << ans << '\n';
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/60
1Accepted0/01ms508 KiB
2Wrong answer0/017ms1988 KiB
3Wrong answer0/31ms316 KiB
4Wrong answer0/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/237ms3672 KiB
8Wrong answer0/235ms3568 KiB
9Wrong answer0/235ms3636 KiB
10Wrong answer0/237ms3528 KiB
11Accepted2/235ms3636 KiB
12Wrong answer0/239ms3712 KiB
13Wrong answer0/229ms3384 KiB
14Wrong answer0/232ms3372 KiB
15Wrong answer0/232ms3396 KiB
16Wrong answer0/232ms3376 KiB
17Wrong answer0/230ms3384 KiB
18Wrong answer0/232ms3352 KiB
19Wrong answer0/237ms3852 KiB
20Wrong answer0/237ms3900 KiB
21Wrong answer0/235ms3976 KiB
22Wrong answer0/235ms3688 KiB
23Wrong answer0/235ms3892 KiB
24Wrong answer0/235ms3744 KiB
25Wrong answer0/235ms3892 KiB
26Wrong answer0/232ms3380 KiB
27Wrong answer0/237ms3892 KiB
28Wrong answer0/235ms3380 KiB
29Wrong answer0/216ms2292 KiB
30Wrong answer0/216ms2116 KiB