Onana_in_XMFLS @ 2024-11-30 16:56:14
dfs写法,为什么前面20分拿不到
#include <bits/stdc++.h>
#define ll long long
#define mem(a,v) memset(a,v,sizeof(a))
using namespace std;
const int maxm = 1e5+5;
int T,n,m,v,c[maxm],d[maxm],a[maxm],b[maxm],x[maxm],ans;
int dx[] = {1,2,1,2};
int dy[] = {1,2,2,1};
bool cbh = false;
void dfs2(int cnt)
{
if(cbh) return;
if(cnt == n+1)
{
for(int i = 1;i < n;++i)
if(x[i] == a[i] && x[i+1] != b[i]) return;
ans++;
cbh = true;
return;
}
if(x[cnt]) dfs2(cnt+1);
else
{
x[cnt] = 1;
dfs2(cnt+1);
x[cnt] = 2;
dfs2(cnt+1);
}
}
void dfs(int cnt)
{
if(cnt == n)
{
cbh = false;
dfs2(1);
return;
}
for(int i = 0;i < 4;++i)
{
a[cnt] = dx[i],b[cnt] = dy[i];
dfs(cnt+1);
}
}
int main(int argc,char *argv[])
{
scanf("%d",&T);
while(T--)
{
ans = 0;
mem(a,0);mem(b,0);mem(c,0);mem(d,0);mem(x,0);
scanf("%d%d%d",&n,&m,&v);
for(int i = 1;i <= m;++i)
{
scanf("%d%d",&c[i],&d[i]);
if(!x[c[i]]) x[c[i]] = d[i];
else if(x[c[i]] != d[i])
{
//cout<<"fuck";
puts("0");
goto nxt;
}
}
dfs(1);
printf("%d\n",ans);
nxt:continue;
}
return 0;
}