QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370837 | #7925. Chayas | Siilhouette | WA | 75ms | 397124kb | C++14 | 1.7kb | 2024-03-29 17:21:53 | 2024-03-29 17:21:55 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include<list>
#include<queue>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=25;
const int M=40010;
const int mod=998244353;
typedef long long ll;
int n,m,tim,cnt,g[N][2];
bitset<25>f[1<<24|3];
ll h[1<<24|3];
vector<int>bitcnt[1<<24|3];
struct Graph{
int tot,vis[N],col[N];
vector<int>a[N][N];
inline void lnk(int x,int y,int z){a[z][x].push_back(y);}
inline bool dfs(int id,int x)
{
vis[x]=tim;
g[cnt][col[x]]|=1<<x-1;
for(auto y:a[id][x])
{
if(vis[y]!=tim)
col[y]=col[x]^=1,dfs(id,y);
else if(col[y]==col[x])
return 0;
}
return 1;
}
}e;
#define lowbit(x) ((x)&(-(x)))
inline int popcnt(int x)
{
int res=0;
while(x)res++,x^=lowbit(x);
return res;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1,x,y,z;i<=m;i++)
scanf("%d%d%d",&x,&y,&z),
e.lnk(x,z,y),e.lnk(z,x,y);
bool ans=1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=cnt;j++)
memset(g[j],0,sizeof(g[j]));
tim++;cnt=0;
for(int j=1;j<=n;j++)
if(i!=j&&e.vis[j]!=tim)
{
cnt++;
ans&=e.dfs(i,j);
if(!ans)break;
}
for(int j=0,lim=1<<cnt;j<lim;j++)
{
int pos=0;
for(int k=0;k<cnt;k++)
pos|=g[k+1][j>>k&1];
f[pos][i-1]=1;
}
if(!ans)break;
}
if(!ans){ puts("0");return 0; }
//cout<<"!"<<endl;
for(int i=0,lim=1<<n;i<lim;i++)
bitcnt[popcnt(i)].push_back(i);
h[0]=1;
for(int i=0;i<n;i++)
for(auto j:bitcnt[i])
for(int k=0;k<n;k++)if(f[j][k])
h[j|(1<<k)]=(h[j|(1<<k)]+h[j])%mod;
printf("%lld\n",h[(1<<n)-1]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 55ms
memory: 397088kb
input:
5 4 1 2 4 2 3 5 3 2 4 1 3 2
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 59ms
memory: 397124kb
input:
4 2 3 1 4 1 4 3
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 55ms
memory: 397092kb
input:
5 5 3 1 2 2 5 4 5 4 3 3 1 5 1 4 5
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 64ms
memory: 397116kb
input:
6 6 1 6 3 2 3 4 5 6 4 3 5 1 1 3 4 1 2 4
output:
6
result:
ok single line: '6'
Test #5:
score: -100
Wrong Answer
time: 75ms
memory: 396996kb
input:
7 10 5 1 6 2 4 7 3 1 2 4 5 7 5 2 6 7 3 6 7 4 6 2 5 7 4 3 7 6 2 3
output:
0
result:
wrong answer 1st lines differ - expected: '8', found: '0'