230462026-01-16 11:09:48algoproTrükkcpp17Wrong answer 0/6037ms3900 KiB
// UUID: 17a48fca-7720-4ffc-9ac9-5d9353e371e5
#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;
        }
    }
    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
base0/60
1Accepted0/01ms316 KiB
2Wrong answer0/018ms2100 KiB
3Wrong answer0/31ms508 KiB
4Wrong answer0/32ms316 KiB
5Wrong answer0/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/235ms3664 KiB
8Wrong answer0/235ms3632 KiB
9Wrong answer0/235ms3620 KiB
10Wrong answer0/235ms3664 KiB
11Wrong answer0/235ms3764 KiB
12Wrong answer0/235ms3636 KiB
13Wrong answer0/229ms3380 KiB
14Wrong answer0/230ms3380 KiB
15Wrong answer0/230ms3380 KiB
16Wrong answer0/232ms3380 KiB
17Wrong answer0/232ms3380 KiB
18Wrong answer0/232ms3412 KiB
19Wrong answer0/237ms3796 KiB
20Wrong answer0/237ms3900 KiB
21Wrong answer0/237ms3892 KiB
22Wrong answer0/235ms3728 KiB
23Wrong answer0/237ms3892 KiB
24Wrong answer0/237ms3640 KiB
25Wrong answer0/237ms3800 KiB
26Wrong answer0/232ms3380 KiB
27Wrong answer0/237ms3828 KiB
28Wrong answer0/235ms3380 KiB
29Wrong answer0/216ms2100 KiB
30Wrong answer0/216ms2100 KiB