设为首页 加入收藏

TOP

Codeforces445B_DZY Loves Chemistry(DFS)
2015-07-24 05:41:32 来源: 作者: 【 】 浏览:4
Tags:Codeforces445B_DZY Loves Chemistry DFS
DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

DZY loves chemistry, and he enjoys mixing chemicals.

DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order.

Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pours a chemical, if there are already one or more chemicals in the test tube that can react with it, the danger of the test tube will be multiplied by 2. Otherwise the danger remains as it is.

Find the maximum possible danger after pouring all the chemicals one by one in optimal order.

Input

The first line contains two space-separated integers n and m \.<??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+CkVhY2ggb2YgdGhlIG5leHQgPGVtPm08L2VtPiBsaW5lcyBjb250YWlucyB0d28gc3BhY2Utc2VwYXJhdGVkIGludGVnZXJzIDxlbT54PC9lbT48ZW0+aTwvZW0+IGFuZCA8ZW0+eTwvZW0+PGVtPmk8L2VtPiAoMT+h3D88ZW0+eDwvZW0+PGVtPmk8L2VtPj88PzxlbT55PC9lbT48ZW0+aTwvZW0+P6HcPzxlbT5uPC9lbT4pLgogVGhlc2UgaW50ZWdlcnMgbWVhbiB0aGF0IHRoZSBjaGVtaWNhbCA8ZW0+eDwvZW0+PGVtPmk8L2VtPndpbGwKIHJlYWN0IHdpdGggdGhlIGNoZW1pY2FsIDxlbT55PC9lbT48ZW0+aTwvZW0+LgogRWFjaCBwYWlyIG9mIGNoZW1pY2FscyB3aWxsIGFwcGVhciBhdCBtb3N0IG9uY2UgaW4gdGhlIGlucHV0LjwvcD4KPHA+CkNvbnNpZGVyIGFsbCB0aGUgY2hlbWljYWxzIG51bWJlcmVkIGZyb20gMSB0byA8ZW0+bjwvZW0+IGluIHNvbWUgb3JkZXIuPC9wPgoKCgpPdXRwdXQKPHA+ClByaW50IGEgc2luZ2xlIGludGVnZXIgoaogdGhlIG1heGltdW0gcG9zc2libGUgZGFuZ2VyLjwvcD4KCgoKU2FtcGxlIHRlc3QocykKCgoKaW5wdXQKPHByZSBjbGFzcz0="brush:java;">1 0 output

1
input
2 1
1 2
output
2
input
3 2
1 2
2 3
output
4
Note

In the first sample, there's only one way to pour, and the danger won't increase.

In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2.

In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that is the numbers of the chemicals in order of pouring).

解题报告

N个化学药品,M对可反应。求最大危险系数。

任一联通块都应该对危险系数产生变化

还以为求最大联通块。

#include 
  
   
#include 
   
     #include 
    
      #define N 55 #define M 12550 using namespace std; struct node { int v,next; } edge[M]; int head[N],n,m,cnt,maxx=0,vis[N]; void add(int u,int v) { edge[cnt].v=v; edge[cnt].next=head[u]; head[u]=cnt++; } void dfs(int s) { vis[s]=1; for(int i=head[s]; i!=-1; i=edge[i].next) { if(!vis[edge[i].v]) { maxx++; dfs(edge[i].v); } } } int main() { int i,j,u,v; while(~scanf("%d%d",&n,&m)) { cnt=0; maxx=0; __int64 dd=1; memset(edge,0,sizeof(edge)); memset(head,-1,sizeof(head)); memset(vis,0,sizeof(vis)); for(i=0; i
     
      

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇codeforces#225DIV2解题报告 下一篇hdu 4722 Good Numbers(初涉数位..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: