Finished c and d, e doesn't check for faulty arrangements

This commit is contained in:
2021-12-05 02:35:53 +01:00
parent b94359378b
commit 61b6cbc2c7
3 changed files with 120 additions and 21 deletions

View File

@@ -2,23 +2,53 @@
using namespace std;
void test_case(int tc){
vector<bool> visitedNodes;
vector<vector<int>> edgeList;
void dfs(int start){
visitedNodes[start] = true;
for(int node : edgeList[start]){
if(!visitedNodes[node]){
dfs(node);
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
int n, m;
cin >> n >> m;
for(int tc = 1; tc <= t; ++tc){
test_case(tc);
if(n != m){
cout << 0 << endl;
return 0;
}
visitedNodes.reserve(n+1);
edgeList.reserve(n+1);
for(int i = 1; i <= m; ++i){
int u, v;
cin >> u >> v;
edgeList[u].push_back(v);
}
long long result = 1;
for(int start = 1; start <= n; ++start){
if(!visitedNodes[start]){
result = (result * 2) % 998244353;
dfs(start);
}
}
cout << result;
cout << flush;
return 0;