227962026-01-15 18:38:01algoproTrükkcpp17Wrong answer 20/6043ms2080 KiB
// UUID: 3e4cc980-69b2-42fb-af3b-da63de8ec683
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MOD = 1e9+7;
vector<vector<int>> graf;
vector<int> paritas;
vector<bool> volt;
vector<int> parent;
bool impossible = false;

void dfs(int csucs, int prev_parity){
	if(prev_parity == 1){
		paritas[csucs] = 2;
	}
	else{
		paritas[csucs] = 1;
	}
	volt[csucs] = true;
	for(int x: graf[csucs]){
		if(x == parent[csucs]){
			continue;
		}
		if(volt[x]){
			if(paritas[csucs] == paritas[x]){
				impossible = true;
			}
		}
		else{
			parent[x] = csucs;
			dfs(x, paritas[csucs]);
		}
	}
}

ll hatvanyoz(int base, int exponent){
	ll hatvany = base;
	ll x = 1;
	for(int j = 0; j <= 30; j++){
		if((exponent >> j) & 1){
			x *= hatvany;
			x %= MOD;
		}
		hatvany *= hatvany;
		hatvany %= MOD;
	}
	return x;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	for(int i = 0; i < t; i++){
		int n, k;
		cin >> n >> k;
		graf.clear();
		graf.resize(n+1);
		paritas.clear();
		paritas.resize(n+1, 0);
		volt.clear();
		volt.resize(n+1, false);
		parent.clear();
		parent.resize(n+1, -1);
		for(int j = 0; j < k; j++){
			int a, b;
			cin >> a >> b;
			graf[a-1].push_back(b);
			graf[b].push_back(a-1);
		}
		int component = 0;
		for(int j = 0; j <= n; j++){
			if(!volt[j]){
				dfs(j, 1);
				component++;
			}
		}
		if(impossible){
			cout << 0 << "\n";
			continue;
		}
		cout << hatvanyoz(2, component-1) << "\n";
	}
}
SubtaskSumTestVerdictTimeMemory
base20/60
1Accepted0/01ms316 KiB
2Accepted0/019ms1076 KiB
3Accepted3/31ms316 KiB
4Wrong answer0/31ms316 KiB
5Accepted3/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Accepted2/241ms1844 KiB
8Wrong answer0/241ms1844 KiB
9Wrong answer0/241ms1844 KiB
10Accepted2/239ms2080 KiB
11Accepted2/239ms1852 KiB
12Wrong answer0/241ms1852 KiB
13Accepted2/230ms1452 KiB
14Wrong answer0/230ms1552 KiB
15Wrong answer0/232ms1516 KiB
16Accepted2/232ms1588 KiB
17Wrong answer0/232ms1592 KiB
18Wrong answer0/232ms1588 KiB
19Accepted2/241ms2036 KiB
20Wrong answer0/241ms2028 KiB
21Wrong answer0/241ms1844 KiB
22Wrong answer0/241ms1844 KiB
23Wrong answer0/241ms1844 KiB
24Wrong answer0/241ms1912 KiB
25Wrong answer0/241ms1844 KiB
26Wrong answer0/232ms1588 KiB
27Wrong answer0/243ms1844 KiB
28Wrong answer0/237ms1588 KiB
29Accepted2/216ms1076 KiB
30Wrong answer0/216ms1464 KiB