题意:http://acm.hdu.edu.cn/showproblem.php?pid=6736

沙漠中的每一个连通块都是一棵仙人掌;一个连通块是一棵仙人掌当且仅当连通块中不存在重边和自环,并且每一条边仅被至多一个简单环覆盖。

经过一番评估,Z 国决定通过删去沙漠中的一些边,最终将沙漠变为森林。这里我们定义森林满足:森林中每一个连通块都是一棵树,而树是边数等于点数减一的连通块。现在给定一个包含 n 个点的沙漠,请你求出 Z 国一共有多少种满足要求的沙漠改造方案。两种方案不同当且仅当方案中被删去的边集不同。由于答案可能很大,请将最终答案对 998244353 取模后输出。

思路:

直接dfs。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
int abss(int a);
int lowbit(int n);
int Del_bit_1(int n);
int maxx(int a,int b);
int minn(int a,int b);
double fabss(double a);
void swapp(int &a,int &b);
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
//const ll INF=(1LL<<60);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int);
const int N=(int)5e5+;
int read(){
int x=,f=;char ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';
return x*f;
}
ll qpow(ll a,ll b,ll mod)
{
ll ans;
// a%=mod;
ans=;
while(b!=)
{
if(b&)
ans=(ans*a)%mod;
b/=;
a=(a*a)%mod;
}
return ans;
} bool vis[N];
ll dep[N];
vector<vector<int> >G(N); ll loop,other,ans;
void dfs(int u,int v)
{
// cout<<u<<' '<<v<<endl;
if(vis[v])
{
if(dep[u]<=dep[v])return;
ans*=qpow(,dep[u]+-dep[v],mod)-;
ans=(ans+mod)%mod;
loop+=dep[u]+-dep[v];
return;
}
vis[v]=;
dep[v]=dep[u]+;
int sz=G[v].size();
for(int i=;i<sz;++i)
{
int to=G[v][i];
if(!dep[v]<=dep[to]&&to!=u)
{
dfs(v,to);
}
}
} int main()
{
int n,way;
while(~sc("%d%d",&n,&way))
{
ans=;loop=other=;
for(int i=;i<=n;++i)
G[i].clear(),dep[i]=vis[i]=;
for(int i=;i<=way;++i)
{
int u,v;
u=read(),v=read();
G[u].push_back(v);
G[v].push_back(u);
}
// bfs({0,1});
dfs(,);
other=way-loop;
ans*=qpow(,other,mod);
ans%=mod;
// if(loop==0)ans=0;
pr("%lld\n",ans);
//cout<<loop<<' '<<other<<endl;
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

最新文章

  1. sql之left join、right join、inner join的区别
  2. Auto Mapper04(MVC中的配置)
  3. Linq_Lambda GroupBy使用笔记
  4. Mac OS X Yosemite安装盘U盘制作
  5. 通过PowerShell获取域名whois信息
  6. oracle 查看表的定义
  7. 3d touch 应用 2 -备用
  8. Ubuntu 查看和杀死进程[转]
  9. OData.NET已在 GitHub上开源
  10. Python实现二叉树的四种遍历
  11. Centos7.2 启用iptables
  12. python之Number
  13. C# md5加密方法
  14. QQ connect client request&#39;s parameters are invalid, invalid openid 问题的解决
  15. 锁(1):spin_lock &amp; mutex_lock的区别? .
  16. XVIII Open Cup named after E.V. Pankratiev. Eastern Grand Prix
  17. maven 本地仓库无法更新到最新版本的jar包
  18. 分布式控制系统Git学习
  19. Django的httprequest对象和httpresponse对象
  20. USB的挂起和唤醒(Suspend and Resume)【转】

热门文章

  1. Linux进程通信之文件
  2. Django基础之命名URL和URL反向解析
  3. redis基础操作概念等笔记
  4. Linux设备驱动程序 之 内核符号表
  5. IDEA + tomcat 远程调试(JPDA)
  6. POJ 2488 -- A Knight&#39;s Journey(骑士游历)
  7. UIGestureRecongnizer 手势拦截 对于特殊需求很有用
  8. Matlab获取文件夹下所有文件名并将数据按矩阵赋值给变量
  9. easyUI之Dialog(对话框窗口)
  10. Fragment向下兼容