Xjoi Online synchronization Training DAY2 T1

Source: Internet
Author: User

"Problem description"

In order to meet the anniversary Moon High School playground began construction. Soon after the playground found a lot of tombs in these tombs there are many treasures. However, the students gradually found that the school's luck began to become particularly bad since the playground construction. Later after investigation found that there is a grave under the tomb due to the playground construction alarmed the magistrate so the school luck will be particularly bad.

You--one of the students of the Moon Middle School in order to save the school in the dream and the magistrate to communicate. The magistrate said, "As long as you can solve this problem I will bless you from everything." You see, there's a treasure in the tomb under the playground numbered. Now you have to choose a collection of treasures that can be either optional or all selected. I have two conditions. The first condition has a condition like ' if you choose the treasure ' then you have to choose the treasure ' the second condition has a condition like ' if you choose the treasure then you can't choose the treasure ' you need to ask out how many options you have in the collection to meet all the criteria. "

As a student of the Moon Middle School you have to answer this question for the school.

"Input Format"

From file treasure. in to read in data.

The first line of input contains three integers representing the number of items the first condition number of the second condition number.

The next line of two positive integers per line means that if you choose a treasure then you must choose the treasure.

The next line of two positive integers per line means that if you choose a treasure then you cannot choose the treasure.

"Output Format"

Output to Treasure.out .

An integer line of output indicates how many options you have to select a collection.

"Sample Input 1"

5 3 3

1 2

1 4

2 5

3 5

4 5

3 5

"Sample Output 1"

6

"Sample Description 1"

Use an integer to represent the treasure that is numbered with this whole number 6 kinds of treasures that meet all the conditions are set to

{},{3},{4},{3,4},{5},{2,5}

And for example {1,4,5} This collection is not satisfying all the conditions it does not meet the first first condition "If you choose Treasure 1 then you have to choose Treasure 2" also does not satisfy the second second condition "If you choose Treasure 4 then you cannot choose Treasure 5".

"Sample Input 2"

40 0 0

"Sample Output 2"

1099511627776

"Sample Description 2"

All the collections are feasible, so the answer is.

"Sample input and Output 3"

See the issued treasure/treasure.in and Treasure/treasure.ans.

"Data size and conventions"

Data points

The scale

The scale

The scale

1

2

3

4

5

6

7

8

9

10

For all data. Please note that using - bit integral type.

Idea: Originally wanted to binary enumeration, and then search the other half, did not expect the TM direct explosion search can, pardoned ah

1#include <algorithm>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <iostream>6 #definell Long Long7 inta[200005][2],first[200005],tot,next[200005],id[200005],go[200005];8 intn,m1,m2;9ll ans=0;Ten intRead () { One     intt=0, f=1;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} -     returnt*F; the } - voidDfsintx,ll sum) { -     if(x==n+1){ -Ans+=sum;return; +     } -     if(!a[x][0]&&!a[x][1]){ +         if(First[x]) { Aa[x][0]++; atDFS (x+1, sum); -a[x][0]--; -a[x][1]++; -             inti; -              for(i=first[x];i;i=Next[i]) { -                 intPur=Go[i]; in                 if(A[pur][!id[i]]) Break; -                 if(pur<x&&!a[pur][0]&&!a[pur][1]) sum>>=1; toa[pur][id[i]]++;  +             } -             if(!i) DFS (x+1, sum); thea[x][1]--; *              for(intj=first[x];j!=i;j=Next[j]) { $                 intPur=Go[j];Panax Notoginsenga[pur][id[j]]--; -             } the}ElseDFS (x+1, sum*2LL); +}Else if(a[x][0]) DFS (x+1, sum); A     Else{ the         inti; +          for(i=first[x];i;i=Next[i]) { -             intPur=Go[i]; $             if(A[pur][!id[i]]) Break; $             if(pur<x&&!a[pur][0]&&!a[pur][1]) sum>>=1; -a[pur][id[i]]++; -         } the         if(!i) DFS (x+1, sum); -          for(intj=first[x];j!=i;j=Next[j]) {Wuyi             intPur=Go[j]; thea[pur][id[j]]--; -         } Wu     } - } About intMain () { $N=read (); M1=read (); m2=read (); -      for(intI=1; i<=m1;i++){ -         intX=read (), y=read (); -tot++; Ago[tot]=y; +id[tot]=1; thenext[tot]=First[x]; -first[x]=tot; $     } the      for(intI=1; i<=m2;i++){ the         intX=read (), y=read (); thetot++; thego[tot]=y; -id[tot]=0; innext[tot]=First[x]; thefirst[x]=tot; the     } AboutDfs1, (LL)1); theprintf"%lld\n", ans); the}

Xjoi Online synchronization Training DAY2 T1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.