显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cstring>
#include<string>
#include<cstdlib>
using namespace std;
int f[10000][10000];
int fun(int x1,int x2,int x3)
{
int duan=0,lian=0;
if(f[x1][x2]==1) duan++;
if(f[x1][x2]==2) lian++;
if(f[x1][x3]==1) duan++;
if(f[x1][x3]==2) lian++;
if(f[x2][x3]==1) duan++;
if(f[x2][x3]==2) lian++;
if(lian==0){
if(duan==0) return 4;
return 1;
}
if(lian==1)
{
if(duan==0) return 2;
if(duan==1) return 1;
if(duan==2) return 0;
}
if(lian==2)
{
if(duan==0) return 1;
if(duan==1) return 1;
}
return 0;
}
int main()
{
freopen("tria.in","r",stdin);
freopen("tria.out","w",stdout);
int n,m,k1,k2,k;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&k,&k1,&k2);
if(k==0) {
f[k1][k2]=1;
f[k2][k1]=1;
}
else
{
f[k1][k2]=2;
f[k2][k1]=2;
}
}
int ans=1,ok=0;
for(int a1=1;a1<=n;a1++)
{
for(int a2=a1+1;a2<=n;a2++)
{
for(int a3=a2+1;a3<=n;a3++)
{
if(a1==a2&&a2==a3)
{
break;
}
ans=ans*fun(a1,a2,a3);
ans=ans%998244353;
}
}
}
cout<<ans;
return 0;
}