227982026-01-15 18:38:44algoproTrükkcpp17Elfogadva 60/6041ms1920 KiB
// UUID: ad4aa057-c3df-435f-98a2-2eb43678b85d
#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);
		impossible = false;
		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";
	}
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base60/60
1Elfogadva0/01ms316 KiB
2Elfogadva0/019ms1076 KiB
3Elfogadva3/31ms316 KiB
4Elfogadva3/31ms316 KiB
5Elfogadva3/31ms316 KiB
6Elfogadva3/31ms316 KiB
7Elfogadva2/241ms1912 KiB
8Elfogadva2/241ms1916 KiB
9Elfogadva2/241ms1916 KiB
10Elfogadva2/239ms1844 KiB
11Elfogadva2/241ms1624 KiB
12Elfogadva2/241ms1776 KiB
13Elfogadva2/230ms1436 KiB
14Elfogadva2/230ms1440 KiB
15Elfogadva2/232ms1476 KiB
16Elfogadva2/232ms1588 KiB
17Elfogadva2/232ms1588 KiB
18Elfogadva2/232ms1444 KiB
19Elfogadva2/241ms1844 KiB
20Elfogadva2/241ms1912 KiB
21Elfogadva2/241ms1844 KiB
22Elfogadva2/241ms1824 KiB
23Elfogadva2/241ms1904 KiB
24Elfogadva2/241ms1920 KiB
25Elfogadva2/241ms1844 KiB
26Elfogadva2/232ms1596 KiB
27Elfogadva2/241ms1844 KiB
28Elfogadva2/237ms1588 KiB
29Elfogadva2/216ms1240 KiB
30Elfogadva2/216ms1076 KiB